Prototype: extern char *strncpy (char *dest, char *src, int n);
Usage: #include <string.h>
Function: Copy the first n bytes of the null-terminated string from SRC to the dest-point array.
Description
If the first n bytes of SRC contain no null characters, the result does not end with a null character.
If the length of SRC is less than n bytes, the dest is filled with null until the n bytes are copied.
The memory regions referred to in SRC and dest cannot overlap and dest must have enough space to hold the SRC string.
Returns a pointer to Dest.
Example:
// strncpy.c
#include <syslib.h>
#include <string.h>
main()
{
char *s="Golden Global View";
char *d="Hello, GGV Programmers";
char *p=strdup(s);
clrscr();
textmode(0x00); // enable 6 lines mode
strncpy(d,s,strlen(s));
printf("%s\n",d);
strncpy(p,s,strlen(d));
printf("%s",p);
getchar();
return 0;
}
Related functions: memccpy,memcpy,stpcpy,strcpy