Hello,
Please see the code below. it combines 2 strings into one.
#include<stdio.h>
#include <string.h>
int main()
{
char a[10], b[10], *p = NULL, *combine(char *s, char *t);
strcpy(a, "horse");
strcpy(b, "fly");
p = combine(a,b);
printf("%s\n",a);
printf("%s\n",b);
printf("%s",p);
}
char *combine(char *s, char *t)
{
int x,y;
char r[50];
strcpy(r,s);
y = strlen(r);
for (x = y; *t != '\0'; ++x)
r[x] = *t++;
r[x] = '\0';
return r;
}
Why can't I print the combined "p" in this code. This is similar to strcat.
Thanks,