-
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!
本文详细介绍了C语言中的strlen()函数用于计算字符串长度,strcpy()用于复制字符串,strcat()用于字符串拼接。通过示例展示了如何在程序中使用这些函数。
1196

被折叠的 条评论
为什么被折叠?



