str-...的函数的模拟实现学习

来源:互联网 发布:软件测试职业规划 编辑:程序博客网 时间:2024/05/20 09:09
int main()
{
int mid = strcmp(s1, s2);
printf("%d\n",mid);
return 0;
int len = strlen("hello,world!");
printf("%d\n",len);//strlen模拟实现:计算长度,/0为止
char arr[10] = { 0 };
strcpy(arr, "hello,world!");
printf("%s\n", arr);  //strcpy模拟实现:复制字符串
}


//strcat 函数模拟实现:连接两个字符串
int main()
{
char arr[20] = "hello";
char *p = " world";
char *pr = strcat(arr, p);
printf("%s\n", pr);
system("pause");
return 0;
}


//strchr函数模拟实现:找字符位置,并且输出后面的字符串
int main()
{
char arr[60] = "the c language is so difficult.";
/*char *pr, c = 'c';*/
char *mid = strchr(arr, 'c');
printf("%s\n",mid);
system("pause");
return 0;
}
//strstr函数模拟实现:将字符串中的某一字符串找到,并输出后面的字符
int main()
{
char *p1 = "the weather is rainy.";
char *p2 = "rainy";
char *c;
c = strstr(p1, p2);
printf("%s\n", c);
system("pause");
return 0;
}
0 0
原创粉丝点击