C
rkingggggg
这个作者很懒,什么都没留下…
展开
-
C语言之-1与0xffffffff
#include <stdio.h>int main(){ unsigned int uint; int i = -1; uint = i; printf("%x %d\n", uint, i); //输出ffffffff -1 uint = 0xffffffff; i = uint; printf("%x %d\n", uint, i); //输...原创 2019-01-11 13:21:25 · 3141 阅读 · 0 评论 -
python和C获取cpu 序列号
C语言获取 cpu序列get_cpu_info.c #include <stdio.h> void cpu_id(char *id) { char s[17]; unsigned int s1,s2; char sel; asm volatile...原创 2019-09-26 17:09:32 · 1374 阅读 · 0 评论 -
C语言之大小端转换
#include <stdio.h>unsigned int reverse_byte(char *c, char num){ unsigned int r = 0; int i; for (i=0; i<num; i++) { r |= (*(c+i)<<(((num-1)*8)-8*i)); } return r;}int main...原创 2019-01-10 10:48:22 · 7756 阅读 · 0 评论 -
C语言之strlen和sizeof
#include <stdio.h>#include <string.h>int main(){ int len; char buf[100] = "hello world"; printf("%u\n", (unsigned int)sizeof(buf)); printf("%u\n", (unsigned int)strlen(buf)); pri...原创 2019-01-10 10:46:44 · 101 阅读 · 0 评论 -
C语言之实现正则1
利用C语言实现正则表达式1此正则表达式只包括‘?’和‘*’正则的匹配规则: '?' 可以匹配任意单字符 '*' 可以匹配任意数的任意字符 例: src = abceeeeeefwgwfwehg re = ab*ehg 匹配成功 src = abceeeeeefwgwfwehg re ...原创 2019-01-10 10:43:00 · 230 阅读 · 0 评论 -
C语言sscanf用法
#include <stdio.h>int main(){ int a, b, c, d, e; char out1[100] = { 0 }; char out2[100] = { 0 }; char out3[100] = { 0 }; char out4[] = "hello world_this is my work!"; sscanf(ou...原创 2019-01-09 19:36:55 · 1210 阅读 · 0 评论 -
leetcode 字符串翻转
ListNode* ReverseList(ListNode* pHead) { 2 ListNode *root=pHead; 3 ListNode *pre=NULL; 4 ListNode *next=NULL; 5 if(pHead==NULL) return NULL; 6 while(root...原创 2019-01-25 10:11:34 · 118 阅读 · 0 评论 -
如何在C语言中遍历结构体成员——基本方法
在C语言中遍历结构中成员;当结构成员的类型相同(或者是所占的字节相同,如uint32和int32)时,如下所示:typedef struct{ int mem0; int mem1; int mem2; int mem3; int mem4; int mem5; int mem6; int mem7; int mem...原创 2019-01-08 20:00:36 · 30904 阅读 · 14 评论 -
C语言之利用nanosleep实现毫秒延时
#include <stdio.h>#include <unistd.h>#include <time.h>#include <sys/time.h>void mssleep(int const time_in_ms){ struct timespec time; struct timespec time_buf;...原创 2019-01-11 14:31:59 · 2844 阅读 · 0 评论 -
C语言之消息队列MQ
send.c#include <stdio.h>#include <fcntl.h>#include <sys/stat.h>#include <mqueue.h>#include <unistd.h>#include <string.h>#define MQ_FILE "/hello" //以/开关,原创 2019-01-11 14:27:52 · 2930 阅读 · 0 评论 -
C语言之getopt 命令行参数获取
#include <stdio.h>#include <unistd.h>int main(int argc, char** argv){ int ch; int opterr = 0; while((ch = getopt(argc, argv, "a:b::dcewf")) != -1) { printf("optind:%d\n", ...原创 2019-01-11 14:22:25 · 313 阅读 · 0 评论 -
C语言之时间localtime
#include <stdio.h>#include <time.h>int main(){ time_t t; struct tm *d; time(&t); printf("%ld\n", (unsigned long)t); d = localtime(&t); printf("%d\n", d->tm_yday); ...原创 2019-01-11 14:17:30 · 1139 阅读 · 0 评论 -
C语言之list当前目录
#include <stdio.h>#include <dirent.h>#include <string.h>#define DIR_NAME "test_dir"int main(){ struct dirent *ep; DIR *dp; dp = opendir(DIR_NAME); if(dp =...原创 2019-01-11 14:05:02 · 238 阅读 · 0 评论 -
C语言之 换零钱
100块钱,利用面值分别为1,5,10,20,50的零钱进行兑换,有多少可能性#include <stdio.h>int mianzhi[5] = {50, 20, 10, 5, 1};//面值int count;//left_money 剩余的钱void change_money(int left_money, int mianzhi_num){ i...原创 2019-01-11 13:52:58 · 5273 阅读 · 0 评论 -
c语言之判断整数是不是2的n次幂
#include <stdio.h>#define is_power_2(x) ((x>0) && (0 == (x&(x-1))))int main(){ for(int i=0; i<63; i++) { printf("%d %d\n", i, is_power_2(i)); }}原创 2019-01-11 13:46:18 · 1176 阅读 · 0 评论 -
C语言之简析malloc与栈,函数与堆
C语言之简析malloc与栈 #include <stdio.h>#include <string.h>#include <stdlib.h>char *getstr(){ char *p = NULL; p = (char *)malloc(sizeof(char)); printf("alloc %p\n", p); return ...原创 2019-01-11 13:40:40 · 567 阅读 · 0 评论 -
通过ctype由python向C语言传递char *,获取新结果
test.c文件#include <stdio.h>void get_new_string(char *dst, int len){ int i=0; for(i=0; i<len; i++){ dst[i] = dst[i]+1; }}gcc -fPIC -c test.cgcc -shared -o tes...原创 2019-09-29 18:59:56 · 3334 阅读 · 0 评论