Dave \Crash\ Dummy
5/15/2011 12:03:00 PM
"janus" <emekamicro@gmail.com> schrieb im Newsbeitrag
news:2dcb273a-7394-494b-8620-9011b4013235@glegroupsg2000goo.googlegroups.com...
> Wolf,
>
> I guess you meant strncpy() function in the above
>
> Janus
No! I meant strcpy, since it it used on guaranteed enough size. Be very
carefull with strncpy! It does not terminate the destination string with a
'\0' character if the source string is longer than the length parameter n.
The following code might give a segment violation!
char FiveChars[6],
*TenChars = "Ten chars ";
strncpy(FiveChars, TenChars, sizeof(FiveChars) - 1);
puts(FiveChars);
strncat guarantees to write a terminating '\0' character.
*FiveChars = 0;
strncat(FiveChars, TenChars, sizeof(FiveChars) - 1);