strcmp代码:
#include <stdio.h>
int main(int argc, const char *argv[])
{
char a[30] = "hello";
char b[30] = "world";
char *p1 = a;
char *p2 = b;
while(*p1==*p2&&*p1!='\0'&&*p2!='\0')
{
p1++;
p2++;
}
printf("%d\n",*p1-*p2);
return 0;
}
运行结果:
strcat代码:
#include <stdio.h>
int main(int argc, const char *argv[])
{
char a[20] = "hello";
char b[20] = "world";
char *p1 = a;
char *p2 = b;
int i;
while(*p1)
{
p1++;
}
while(*p2!='\0')
{
*p1=*p2;
p1++;
p2++;
}
*p1='\0';
printf("%s\n",a);
return 0;
}
运行结果: