[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


strncpy

Copy a specified number of characters.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <string.h>
char *strncpy(char *dest, 
   const char *source, size_t n);
Parameters:

Parameters for this facility are:

dest  
char *  
The destination string  
source  
const char *  
The source to copy  
n  
size_t  
The maximum length to copy  

Remarks:

The strncpy() function copies a maximum of n characters from the character array pointed to by source to the character array pointed to by dest. Neither dest nor source must necessarily point to null terminated character arrays. Also, dest and source must not overlap.

If a null character ('\0') is reached in source before n characters have been copied, strncpy() continues padding dest with null characters until n characters have been added to dest.

The function does not terminate dest with a null character if n characters are copied from source before reaching a null character.

Return:

strncpy() returns the value of dest.

See Also:

"memcpy"

"memmove"

"strcpy"

Example of strncpy usage.:
#include <string.h>
#include <stdio.h>

int main(void)
{
	char d[50];
	static char s[] = "123456789ABCDEFG";

	strncpy(d, s, 9);
	puts(d);

	return 0;
}

Output:
123456789


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000