C strncpy() Function

Last Updated:

C strncpy()

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

Example

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; }

Syntax

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

Parameter Values

ValueTypeExplanation
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

ValueExplanation
String Returns the copied string up to the specified length.

Share this Page

Meet the Author