标签:
以前的记录都在电子笔记里,倒不如拿出来,有错的地方和大家交流。
1 #include <stdio.h> 2 int main(int argc, const char *argv[]) 3 { 4 char hexBuff[128]; 5 sprintf(hexBuff, "%x%x",0x32,0x4d); 6 printf("%s\n",hexBuff); 7 printf("%c\n",hexBuff[0]); 8 printf("%c\n",hexBuff[1]); 9 printf("%c\n",hexBuff[2]); 10 printf("%c\n",hexBuff[3]); 11 printf("%x\n",henBuff[0]); 12 return 0; 13 }
1 #include <stdio.h> 2 #include <string.h> 3 int fun(char * str){ 4 char tmp[8]; 5 int index = 0; 6 while( * str){ 7 tmp[index++] = * str++; 8 if(index == 7){ 9 printf("%s\n", tmp); 10 if(strncmp(tmp, "0000000", 7) == 0){ 11 printf("game over....\n"); 12 } 13 memset(tmp,0,8); 14 index = 0; 15 } 16 } 17 return 1; 18 } 19 int main(int argc, const char *argv[]) 20 { 21 char str[] = "1234567234567800000001234568"; 22 fun(str); 23 return 0; 24 }
1 int fun(char * str){ 2 char tmp; 3 char array[10]; 4 int count = 0; 5 int index = 0; 6 while( * str){ 7 tmp = *str++; 8 array[count] = tmp; 9 if(*str == tmp){ 10 array[++count] = *str; 11 }else { 12 count = 0; 13 printf("%s\n", array); 14 memset(array, 0, 10); 15 tmp = 0; 16 } 17 } 18 return 1; 19 }
1 BOOL DeteleNode(Node *pHeader, DataType Value) 2 { 3 if (pHeader == NULL) return; 4 BOOL bRet = FALSE; 5 Node *pNode = pHead; 6 while (pNode != NULL) 7 { 8 if (pNode->data == Value) 9 { 10 if (pNode->front == NULL) 11 { 12 pHeader = pNode->next; 13 pHeader->front = NULL; 14 } 15 else 16 { 17 if (pNode->next != NULL) 18 { 19 pNode->next->front = pNode->front; 20 } 21 pNode->front->next = pNode->next; 22 } 23 Node *pNextNode = pNode->next; 24 delete pNode; 25 pNode = pNextNode; 26 bRet = TRUE; 27 //不要 break 或 return, 删除所有 28 } 29 else 30 { 31 pNode = pNode->next; 32 } 33 } 34 return bRet; 35 } 36 37 void DE(Node *pHeadA, Node *pHeadB) 38 { 39 if (pHeadA == NULL || pHeadB == NULL) 40 { 41 return; 42 } 43 Node *pNode = pHeadA; 44 while (pNode != NULL) 45 { 46 if (DeteleNode(pHeadB, pNode->data)) //在B中将A中的data删除掉 47 { 48 if (pNode->front == NULL) //同时删除A中的data 49 { 50 pHeadA = pNode->next; 51 pHeadA->front = NULL; 52 } 53 else 54 { 55 pNode->front->next = pNode->next; 56 if (pNode->next != NULL) 57 { 58 pNode->next->front = pNode->front; 59 } 60 } 61 Node *pNextNode = pNode->next; 62 delete pNode; 63 pNode = pNextNode; 64 } 65 else 66 { 67 pNode = pNode->next; 68 } 69 } 70 }
6.不定参数函数的实现
1 int sum(int num, ...) 2 { 3 int *p = &num + 1; 4 int ret = 0; 5 while(num--) 6 { 7 printf("%d\n", num); 8 ret += *p++; 9 } 10 return ret; 11 } 12 int main(int argc, char* argv[]) 13 { 14 printf("%d\n", sum(3, 5, 7, 9)); 15 return 0; 16 }
1 int main(int argc, const char *argv[]) 2 { 3 char *p = "abc"; 4 char p1[] = "wan"; 5 printf("p = %u p1 = %u\n", strlen(p), strlen(p1)); 6 printf("sizeof(int) = %d\n", sizeof(int)); 7 return 0; 8 }
答案:p = 3, p1 = 3; sizeof(int) = 4.
标签:
原文地址:http://www.cnblogs.com/youthshouting/p/4277945.html