1、strcpy 函数
| #include <stdio.h> |
| #include <string.h> |
| int main(void) |
| { |
| char boy_Name1[20]; |
| const char* boy_Name2 = "Mingming "; |
| strcpy(boy_Name1, boy_Name2); |
| printf("%s", boy_Name1); |
| } |
2、strlen函数
| #include <stdio.h> |
| #include <string.h> |
| |
| int main(void) |
| { |
| const char* boy_Name = "Chu mingming "; |
| int name_Length = strlen(boy_Name); |
| printf("%d", name_Length); |
| } |
3、strcmp函数
| #include <stdio.h> |
| #include <string.h> |
| |
| int main(void) |
| { |
| const char* string_1 = "ABCDE"; |
| const char* string_2 = "FGHIJ"; |
| int result = strcmp(string_1, string_2); |
| if (result < 0) |
| printf("string_1 is less than string_2"); |
| else if (result > 0) |
| printf("string_1 is more than string_2"); |
| else |
| printf("string_1 is equal to string_2"); |
| } |
4、strcat函数
| #include <stdio.h> |
| #include <string.h> |
| |
| int main(void) |
| { |
| char first_Word[20] = "Hello"; |
| const char* blank = " "; |
| const char* second_Word = "World"; |
| strcat(first_Word, blank); |
| strcat(first_Word, second_Word); |
| printf("%s", first_Word); |
| } |
5、strchr函数
| #include <stdio.h> |
| #include <string.h> |
| |
| int main () |
| { |
| const char str[] = "https://www.runoob.com"; |
| const char ch = 'o'; |
| char *ptr; |
| |
| ptr = strchr(str, ch); |
| |
| if (ptr != NULL) { |
| printf("字符 'o' 出现的位置为 %ld。\n", ptr - str + 1); |
| printf("|%c| 之后的字符串是 - |%s|\n", ch, ptr); |
| } else { |
| printf("没有找到字符 'o' 。\n"); |
| } |
| return(0); |
| } |
6、strcasecmp函数
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| |
| void main() |
| { |
| long ulCmpRet1; |
| long ulCmpRet2; |
| char *string_A ="This is string A"; |
| char *string_a ="This is string a"; |
| char *string_B ="This is string B"; |
| |
| ulCmpRet1 = strcasecmp(string_A,string_a); |
| ulCmpRet2 = strcasecmp(string_A,string_B); |
| printf("%ld\n",ulCmpRet1); |
| printf("%ld\n",ulCmpRet2); |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY