strncpy, _fstrncpy

Description

Copy characters of one string to another.

#include <string.h> Required only for function declarations  

char *strncpy( char *string1, const char *string2, size_t count );

char __far * __far _fstrncpy( char __far *string1, const char __far *string2,
size_t count );

string1 Destination string  
string2 Source string  
count Number of characters copied  

Remarks

The strncpy and _fstrncpy functions copy count characters of string2 to string1 and return string1. If count is less than the length of string2, a null character ('\0') is not appended automatically to the copied string. If count is greater than the length of string2, the string1 result is padded with null characters ('\0') up to length count.

Note that the behavior of strncpy and _fstrncpy is undefined if the address ranges of the source and destination strings overlap.

The _fstrncpy function is a model-independent (large-model) form of the strncpy function. The behavior and return value of _fstrncpy are identical to those of the model-dependent function strncpy, with the exception that all the arguments and return values are far.

Return Value

The return values for these functions are described above.

Compatibility

strncpy

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

_fstrncpy

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

strcat, strcmp, strcpy, strncat, strncmp, _strnicmp, strrchr, _strset, strspn

Example

/* STRNCPY.C */

#include <string.h>

#include <stdio.h>

void main( void )

{

char string[100] = "Cats are nice usually";

printf("Before: %s\n", string );

strncpy( string, "Dogs", 4 );

strncpy( string + 9, "mean", 4 );

printf("After: %s\n", string );

}

Output

Before: Cats are nice usually

After: Dogs are mean usually