strlen()可以得到字符数组中第一个\0前的字符的个数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 char str [10]; 6 gets(str); 7 int len=strlen(str); 8 printf("%d\n",len); 9 return 0; 10 }
strcmp()
strcmp()函数返回两个字符串大小的比较结果,按字典序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 char str1[50],str2[50]; 6 gets(str1); 7 gets(str2); 8 int cmp=strcmp(str1,str2); 9 if(cmp<0) printf("str1<str2\n"); 10 else if (cmp>0) printf("str1>str2\n"); 11 else printf("str1==str2\n"); 12 return 0; 13 14 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 char str1[50],str2[50]; 6 gets (str1); 7 gets(str2); 8 strcpy(str1,str2); 9 puts (str1); 10 return 0; 11 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 char str1[50],str2[50]; 6 gets(str1); 7 gets(str2); 8 strcat(str1,str2); 9 puts(str1); 10 return 0; 11 12 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 /*将字符数组str中的内容以%d的格式写到n中*/ 5 int main(){ 6 int n; 7 char str[100]="123"; 8 sscanf(str,"%d",&n); 9 printf("%d\n",n); 10 return 0; 11 12 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 int n=233; 6 char str[100]; 7 sprintf(str,"%d",n); 8 printf("%s\n",str); 9 return 0; 10 }