-strncmp() is a string function that are able to compare two string upto nth index.
-It is predefined in string.h header file.
Syntax-
strncmp(str1,str2,n)
-Here str1 and str2 is the two string which we compare.
-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);
printf("Enter second string\n");
scanf("%s",&s2);
if(strncmp(s1,s2,4))
printf("Not same");
else
printf("Same");
}
Enter first string
Mystring
Enter second string
Mystring
Same
Enter first string
Mystring
Enter second string
Mys
Not same
Enter first string
Mystring
Enter second string
Myst
Same