strncpy, _mbsncpy, wcsncpy
Remonter à String.h - Index
Header File
string.h, mbstring.h
Category
Memory and String Manipulation Routines, Inline Routines
Prototype
char *strncpy(char *dest, const char *src, size_t maxlen);
wchar_t *wcsncpy(wchar_t *dest, const wchar_t *src, size_t maxlen);
unsigned char *_mbsncpy(unsigned char *dest, const unsigned char *src, size_t maxlen);
Description
Copies a given number of bytes from one string into another, truncating or padding as necessary.
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.
Return Value
strncpy returns dest.
Example
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strncpy(string, str1, 3);
string[3] = '\0';
printf("%s\n", string);
return 0;
}
Portability
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
strncpy |
+ |
+ |
+ |
+ |
_mbsncpy |
+ |
|||
wcsncpy |
+ |
+ |
+ |