S
smnoff
How does( or should user use) strncpy() to allocate enough memory space for
the destination string, s1?
I guess I am having trouble using strncpy as it seems to be giving me
errors.
And just as well, I don't know the value of n until the program runs, so it
needs to be dynamically allocated.
Then again I hard coded n to be number like3 just to even see if that works.
470 char *
471 strncpy(char *s1, const char *s2, size_t n)
472 {
473 char *os1 = s1;
474
475 n++;
476 while (--n != 0 && (*s1++ = *s2++) != '\0')
477 ;
478 if (n != 0)
479 while (--n != 0)
480 *s1++ = '\0';
481 return (os1);
482 }
the destination string, s1?
I guess I am having trouble using strncpy as it seems to be giving me
errors.
And just as well, I don't know the value of n until the program runs, so it
needs to be dynamically allocated.
Then again I hard coded n to be number like3 just to even see if that works.
470 char *
471 strncpy(char *s1, const char *s2, size_t n)
472 {
473 char *os1 = s1;
474
475 n++;
476 while (--n != 0 && (*s1++ = *s2++) != '\0')
477 ;
478 if (n != 0)
479 while (--n != 0)
480 *s1++ = '\0';
481 return (os1);
482 }