Using strncmp in C language

The function strncmp has three arguments. The first two arguments are two strings. The third is an integer that specifies the number of characters to compare.

 #include <stdio.h>
 #include <string.h>
 
 int main()
 {
    char s1[80],s2[80];
    int outcome;
 
    printf("Enter two strings : ");
    scanf("%s%s",s1,s2);
    outcome=strncmp(s1,s2,2);
    printf("nValue returned by strncmp is %d.n",outcome);
    return 0;
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.