strncpy question

Paul T. Shannon pts at watt.acc.Virginia.EDU
Thu May 11 01:39:35 AEST 1989


I have a question on the strncpy library function. (The same question applies to
strcpy as well.) This program fragment seems to be the recommended usage:

       char *original, *copy;   /* assume that original points to a string */
       int stringLength;

       stringLength = strlen (original);
       copy = malloc (stringLength + 1);  /* allow room for terminating null */
       copy = strncpy (copy, original, stringLength); 

Why is this function written so that the pointer to the destination string is 
both
       1. passed as  an argument to the function, and
       2. returned by the function?

Paul Shannon  



More information about the Comp.lang.c mailing list