strncmp function of C works same as strcmp( ) function which is used in C program for comparing two string together with one extra condition...
![]() |
| strcmp() in C |
- strncmp( ) function in C
- Header file for strncmp( ) in C
- Syntax of strncmp( ) function in C
- Return value of strncmp( ) function in C
- Example of strncmp( ) function in C
strncmp( ) function in C
strncmp( ) function is also known as a built in function or standard library function of C but it is widely know as string function. strncmp( ) function is basically used to compare two string assertion(argument) character by character by using 'n' parameters that means strncmp function compare both strings until n parameters.
strncmp( ) function is also compare two string together on the basis of ASCII value of each character, which are already define in C compiler.
Return value of strcmp( ) function in C
strncmp( ) function may be return three possible integer value based on the comparison...
- Zero( 0 ) : This value is return when ASCII value of both strings are equal.
- Greater than Zero( >o) : When the ASCII value of first string is greater than second string.
- Less than Zero( <0) : When the ASCII value of second string is greater than first string.
Header file of strncmp( ) function in C
strncmp( ) function is a built in function of C and it is define in <string.h> header file.
syntax of strncmp( ) function in C
strncmp( str1,str2,n);
Example of strncmp( ) function in C
#include<stdio.h>
#include<string.h>
int main()
{
int n;
char str[15]="Akash";
char str1[15]="Ashish";
n=strncmp(str,str1,1);
if(n>0)
{
printf("str is greater than str1");
}
else if(n<0)
{
printf("str is less than str1");
}
else
{
printf("both string are equal");
}
return 0;
}
____________________________________
![]() |
| Strncmp( ) Example |
Conclusion
This function is basically used to compare to string together by using 'n' parameters.

