Of course we don't really need this return(tmp),but it
does help us handle the error condition where malloc fails.
In the above we have assumed that malloc always succeeds.
strcpy() must handle failure by returning the NULL pointer.
tmp = (char*) malloc (1+strlen(s));
for ( i = 0; *(s+i) != '\0'; i++ )
*(tmp+i) = *(s+i);
return (tmp);
Outside in the calling program one might well actually use
strcpy as follows:
if (strcpy (tmp, s) != NULL) {.........}
|