strncpy() Copy a Specified Number of Characters
#include <string.h> Required for declarations only
char *strncpy(string1,string2,n);
char *string1; Destination string
char *string2; Source string
unsigned int n; Number of characters copied
strncpy() copies exactly 'n' characters from 'string2' to 'string1'.
The terminating null character ('\0') is not automatically appended
if 'n' is less than the length of 'string2'. If 'n' is greater than
the length of 'string2', 'string1' is padded with null characters
after the copy, up to the length 'n'.
Returns: A pointer to the copied string.
-------------------------------- Example ---------------------------------
The following statements copy 'n' characters of string2 to string1
and print out the result.
#include <string.h>
#include <stdio.h>
char *copy;
char string1[50];
char string2[25] = "reference guide";
main()
{
copy = strncpy(string1,string2,10);
printf("%s\n",copy);
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster