strncpy
char * strncpy ( char * dest, const char * src, sizet_t num ); | string.h |
cplusplus.com |
Copy characters from one string to another.
Copies the first num characters of src to dest.
No null-character is implicitly appended to dest after copying process.
So dest may not be null-terminated if no null-caracters are copied
from src.
If num is greater than the length of src, dest is padded with zeros
until num.
Parameters.
Return Value.
dest is returned.
Portability.
Defined in ANSI-C.
Example.
/* strncpy example */
#include <stdio.h>
#include <string.h>
main ()
{
char str1[]= "To be or not to be";
char str2[6];
strncpy (str2,str1,5);
str2[5]='\0';
puts (str2);
return 0;
}
Output:
To be
See also.
strcpy,
strcat,
strncat,
strstr,
memcpy