stncpy( ) function in C which is basically used to copy one string to another by using n parameters(variables).
![]() |
| strncpy() in C |
Through this article we are going to discuss strncpy( ) function in detail in which we will cover following topics.
Topics:-
- strncpy( ) function in c
- strncpy( ) function in c example
- strncpy( ) function in c syntax
- header file for strncpy( ) function in c
strncpy( ) function in C
strncpy( ) function is also known as a built in function or standard library function of C but it is widely know as string function, which are basically used to copy only the left most 'n' character of source string to the target string variable.
it is also act like string assignment operator in C language.
Header file for strncpy( ) in C
strncpy( ) function is a built in function of C language which are define in <string.h> header file.
Syntax of strncpy( ) in C
strncpy(string1,string2,size_num);
Example of strncpy( ) in C
#include<stdio.h>
#include<string.h>
int main()
{
char str[15];
char str1[15]="AceinStudy";
strncpy(str,str1,10);
printf("Now string %s in str",str);
return 0;
}
____________________________________
![]() |
| Strncpy( ) example |
Conclusion
strncpy( ) function in C is basically used to copy the string from one string to other by using n parameters.

