string.h
概要
glibc 的 string.h 头文件包含如下内容。
函数
- size_t strlen (const char *s) 返回一个字符串的长度,但是要特别注意一下 strlen 和 sizeof 的区别。
const char message[24] = "hello";
const char *ps = message;
printf("strlen(string) = %lu \n", strlen(message)); // strlen(string) = 5
printf("strlen(ps) = %lu \n", strlen(ps)); // strlen(ps) = 5
printf("sizeof(message) = %lu \n", sizeof(message)); // sizeof(message) = 24
printf("sizeof(ps) = %lu \n", sizeof(ps)); // sizeof(ps) = 8