目录
1、实现strcat函数
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char arr[30] = " ";
char brr[30] = " ";
printf("请输入字符串a>>");
gets(arr);
printf("请输入字符串b>>");
gets(brr);
char *p1 = arr;
char *p2 = brr;
int len = strlen(arr);
while(*p2)
{
*(p1+len) = *p2;
p1++;
p2++;
}
puts(arr);
return 0;
}
2、实现strcmp函数
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char arr[30] = " ";
char brr[30] = " ";
printf("请输入字符串a>>");
gets(arr);
printf("请输入字符串b>>");
gets(brr);
char *p1 = arr;
char *p2 = brr;
int flag = 0;
while(*p1 != '\0' && *p2 !='\0')
{
if(*p1 > *p2)
{
flag = 1;
break;
}
else if(*p1 < *p2)
{
flag = -1;
break;
}
else
{
flag = 0;
}
*p1++;
*p2++;
}
printf("比较的结果为:%d\n",flag);
return 0;
}