实现字符串的连接,把p2所指的字符串连接到p1所指的字符串后,*/
#include <stdio.h>
void fun(char p1[],char p2[])
{
while (*p1)
{
p1++;
}
while (*p2)
{
*(p1)=*(p2);
p1++;
p2++;
}
p1='\0';
}
main()
{
char s1[80],s2[40];
printf("Enter s1 and s2 ");
printf("\n");
scanf("%s%s",s1,s2);
printf ("s1=%s\n",s1);
printf("s2=%s\n",s2);
fun(s1,s2);
printf("After invoking :\n");
printf("%s\n",s1);
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void fun (char p1[],char p2[])
{
int i,k,m;
k=strlen(p1);
m=strlen(p2);
for (i=0;i<m;i++)
{p1[k+i]=p2[i];}
p1[k+m]='\0';
}
main()
{
char s1[80],s2[40];
printf("Enter s1 and s2 ");
printf("\n");
scanf("%s%s",s1,s2);
printf ("s1=%s\n",s1);
printf("s2=%s\n",s2);
fun(s1,s2);
printf("After invoking :\n");
printf("%s\n",s1);
}