-strncpy() is a string function that are able to copy the data of one string into the other string upto nth term.
-It is predefined in string.h header file.
Syntax-
strncpy(str1,str2,n)
-Here str1 and str2 is two string and data of str1 is copied in str2.
-n is the index value.
program-
#include< stdio.h>
#include< string.h>
int main()
{
char s1[20],s2[20];
//input of string
printf("Enter first string\n");
scanf("%s",&s1);
strncpy(s2,s1,5);
printf("Second string is %s",s2);
}
Enter first string
Mystring
Second string is Mystr