1. 写出四个函数族(strlen、strcpy、strcmp、strcat)
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
/*
写出四个函数族(strlen、strcpy、strcmp、strcat)
*/
char str[30] = "";
char str1[30] = "";
char str2[30] = "";
char s1[30] = "";
char s2[30] = "";
char *p = str;
char *p1 = str1;
char *p2 = s1;
int count = 0,sub = 0;
printf("请输入字符串:");
scanf("%s",str);
printf("请输入第二个字符串:");
scanf("%s",s1);
int len = strlen(str);
int len1 = strlen(s1);
while(*p++)
{
count++;
}
printf("%d\t%d\n",count,len);
p=str;
strcpy(str2,str);
while(*p != 0)
{
*p1 = *p;
p++;
p1++;
}
*p1 = *p;
printf("%s\t%s\n",str1,str2);
p = str;
p2 = s1;
while(sub == 0)
{
sub = *p - *p2;
p++;
p2++;
}
printf("%d\t",sub);
printf("%d\n",strcmp(str,s1));
p = str;
p2 = s1;
strcpy(s2,s1);
strcat(s2,str);
while(*p != 0)
{
*(p2+len1) = *p;
p++;
p2++;
}
*(p2+len1) = *p;
printf("%s\t%s\n",s1,s2);
return 0;
}