My homework problem is to make a program putting 3 strings together using strcpy, strcat, sprintf at least once each.
I'm wondering if I can use all those three without any garbage code. I've tried using strchr to use sprintf for putting strings together, but the pointer location changed so couldn't print out the whole thing.
char str1[MAX];
char str2[MAX];
char str3[MAX];
char str4[MAX];
gets(str1);
gets(str2);
gets(str3);
strcat(str1, str2);
strchr(str1, '\0');
sprintf(str1, "%s", str3);
strcpy(str4, str1);
puts(str4);
I also want to know if there is any difference in their use between strcpy and sprintf in this case.
 
     
     
    