字符串函数案例及其使用注意事项和细节
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 char str1[12] = "Hello"; 6 char str2[12] = "World"; 7 char str3[12]; 8 int len; 9 strcpy(str3, str1); //复制str1到str3 10 printf("strcpy(str3, str1):%s\n", str3); 11 strcat(str1, str2); //连接str1和str2 12 printf("strcat(str1, str2):%s\n", str1); 13 len = strlen(str1); //连接后str1的总长度 14 printf("strlen(str1):%d\n", len); 15 return 0; 16 }
注意事项和细节:
经典错误案例: