/* p2.c 1. test the function append by compiling and runing the program. Fix the problem (there are many ways to fix the problem, ask for help if you can't figure out what the problem is). 2. Rewite append so that it uses pointers instead of array syntax (instead of s1[i], use *s1, etc). Once again, ask for help if you don't know how to do this! 3. Rewrite append so that it uses the library functions strcpy and strcat (at the command prompt type "man strcpy" or "man strcat" for details about these functions. You will need to add "#include " to your program to tell the compiler about these functions. */ #include /* function append appends two strings and returns the result (as a pointer to a new string) won't work unless the strings are no larger than 10 chars each */ char *append(char *s1, char *s2) { char both[25]; int i,j; if ((strlen(s1)>10) || (strlen(s2)>10)) { printf("Invalid string length (too big)\n"); return(NULL); } i=0; /* copy the first string to both */ while (s1[i]!=0) { both[i] = s1[i]; i++; } /* now append the second string */ j=0; while (s2[j]!=0) { both[i] = s2[j]; i++; j++; } return(both); } int main() { char *s = append("Hello ", "World"); if (s != NULL) printf("Result is %s\n",s); return(0); }