-
strlen函数:
- 功能:
strlen
函数用于计算字符串的长度,即返回字符串中字符的个数,不包括结束符\0
。 - 原型:
size_t strlen(const char *str);
- 示例:
#include <stdio.h> #include <string.h> int main() { const char *str = "Hello, World!"; size_t length = strlen(str); printf("Length of the string: %zu\n", length); return 0; }
- 功能:
返回:13
-
strcpy函数:
- 功能:
strcpy
函数用于将一个字符串复制到另一个字符串中,包括字符串的结束符\0
。 - 原型:
char *strcpy(char *dest, const char *src);
- 示例:
#include <stdio.h> #include <string.h> int main() { char source[] = "Hello, World!"; char destination[20]; strcpy(destination, source); printf("Copied string: %s\n", destination); return 0; }
- 功能:
返回Copied string: Hello, World!
-
strcat函数:
- 功能:
strcat
函数用于将一个字符串追加到另一个字符串的末尾。 - 原型:
char *strcat(char *dest, const char *src);
- 示例:
#include <stdio.h> #include <string.h> int main() { char destination[20] = "Hello, "; char source[] = "World!"; strcat(destination, source); printf("Concatenated string: %s\n", destination); return 0; }
- 功能:
返回Concatenated string: Hello, World!