strncpy, _fstrncpy
raw OCR
Copies a given number of bytes from one string into another, truncating or padding as necessary.
Defined in header <stdio.h>
Syntax
#include <stdio.h>
Near version: char *strncpy(char *dest, const char *src,size_tmaxlen);
Far version: char far * far_fstrncpy(char far *dest,constchar far *src,
size_t maxlen)
strncpy copies up to maxlen characters from src into dest, truncating or
null-padding dest. The target string, dest,might not be null-terminated if
the length of src is maxlen or more.
Portability
| DOS | UNIX | Windows | ANSI C | C++ only | |
|---|---|---|---|---|---|
| Near version | ■ | ■ | ■ | ■ | |
| ■ | ■ |
Return value
strncpy returns dest.
Example
include <stdio.h>
#include <string.h>
int main (void)
char string [10];
char *strl = "abcdefghi";
strncpy (string, strl, 3);
string[3] = '\0';
printf ("%s\n", string);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdio.h/strncpy/
· short form /3.1/strncpy/