What is strcmp() function in C language

strcmp( ) function is basically used in c program for comparing two string assertion(arguments) together.

What is strcmp() function in C language
strcmp( ) in C

Through this article we will try to cover whole basis queries about strcmp( ) in detail so if you have any doubt related to this topic then you will be go with this article....

Topics:-

  1. strcmp( ) function in c
  2. strcmp( ) function in c example
  3. strcmp( ) function in c syntax
  4. header file for strcmp( ) function in c
  5. what does strcmp( ) return ?

strcmp( ) function in C

strcmp( ) function is also known as a built in function or standard library function of C but it is widely know as string function. strcmp( ) function is basically used to compare two string assertion(argument) character by character. strcmp( ) function 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

strcmp( ) function may be return three possible integer value based on the comparison...
  1. Zero( 0 ) : This value is return when ASCII value of both strings are equal.
  2. Greater than Zero( >o) : When the ASCII value of first string is greater than second string.
  3. Less than Zero( <0) : When the ASCII value of second string is greater than first string.

Header file of strcmp( ) function in C

strcat( ) function is a built in function of C and it is define in <string.h> header file.

syntax of strcmp( ) function in C

strcmp( str1,str2);

Example of strcmp( ) function in C

#include<stdio.h>
#include<string.h>
int main()
{
  int n;
  char str[15]="Akash";
  char str1[15]="Ashish";
  n=strcmp(str,str1);
  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;
}

____________________________________

Example of strcmp() function in C
____________________________________

Conclusion

strcmp( ) function is basically used in c program for comparing two string character by character on the basis of ASCII value.
Post a Comment (0)
Previous Post Next Post