#include /* defines NULL, but can also just use # define NULL 0 */ main() {char str[80]; char *str2, *strsave(); /* need to declare functions that return non-ints. if main is last, no declarations needed. no arguments included in declaration. */ printf("Enter a string> "); scanf("%s",str); /* notice no & for ptrs, & for non-ptr values */ str2=strsave(str); printf ("\n%s has a length of %d\nstr2 is %s\n",str,strlength(str), str2); } /* these examples modified for K&R, chapter 5 */ /* remember functions are int by default */ /* the following header in K&R is written slightly differently. Either is ok, but the text uses a slightly older style of C. It has the following: strlength(s) char * s; where the parameter type is declared below the parameter list */ /* finally, strlen is built in, so there is really no need for this function*/ strlength(char *s) { char *p = s; while (*p != '\0') p++; return (p-s); } /* this version of strsave may be helpful for your assignment. */ char *strsave(s) char *s; /* notice type is BELOW header; this is common in C */ {char *p; if ((p = (char *) malloc(strlength(s)+1)) != NULL) strcpy(p, s); return p; }