几个最常用的字符串函数
(本条路线统一用 gcc -std=c11 -O0 -Wall 编译)长度、拷贝、拼接、比较:
#include <stdio.h>
#include <string.h>
int main(void) {
const char *s = "hello";
char buf[16];
strcpy(buf, s);
strcat(buf, "!");
printf("%zu/%zu/%d\n", strlen(s), strlen(buf), strcmp(s, "hello") == 0);
return 0;
}
全部评论