C strncpy() Function

Last Updated:

C strncpy()

The strncpy() function copies a string from source to destination up to the specified length.


C Compiler
#include <stdio.h> #include <string.h> int main() { char mail[50] = "johndoe@gmail.com"; char copyMail[50] = ""; strncpy(copyMail, mail, 7); printf("copyMail is: %s", copyMail); return 0; }


char *strncpy(char *dest, char *src, int n)

Parameter Values

dest Required Specifies the destination string.
src Required Specifies the source string.
n Required Specifies the length of the source string to be copied to the destination string.

Return Value

String Returns the copied string up to the specified length.

Share this Page

Meet the Author