strlen() 计算字符串长度(打印的是能看见的字符长度;sizeof()打印的是字符串物理长度,默认算上’\0’)
char testLen[] = "hello world";
unsigned long count = strlen(testLen);
printf("%lu\n", count);
strcpy() 字符串拷贝:把后面的字符串拷贝给前面的字符串 (并非把内容复制,而是拷贝指针)
原型:strcpy(char , const char )
char testCpy1[] = " ";
char testCpy2[] = "hello";
strcpy(testCpy1, testCpy2);
for (int i = 0; i < 6; i++) {
printf("%c", testCpy1[i]);
}
strcat() 字符串拼接
原型:strcat(char , const char )
char testCat1[] = "hello";
char testCat2[] = "world";
strcat(testCat1, testCat2);
printf("%s", testCat1); //%s 输出字符串,按顺序扫描字符串,当遇到'\0'时,终止扫描
strcmp() 字符串比较
原型:strcmp(const char , const char )
char testCmp1[] = "hello";
char testCmp2[] = "hellwo";
int result = strcmp(testCmp1, testCmp2); //strcmp()函数需要一个返回值
printf("%d", result); //比较的是第一个不同的字母的ASCII码表的值