C strcmp function

« Previous

Synopsis:

Example

#include <stdio.h>
int strcmp(char *string1, char *string2); 

Description:

The strcmp function compares the contents of string1 and string2 and returns a value indicating their relationship.

Return Value

  • if Return value if < 0 then it indicates string1 is less than string2

  • if Return value if > 0 then it indicates string2 is less than string1

  • if Return value if = 0 then it indicates string1 is equal to string1

Example

Example

#include <stdio.h>
int main() {
  char string1[20];
  char string2[20];
  strcpy(string1, "Learn");
  strcpy(string2, "NewFile.oo");
  printf("Return Value is : %d\n", strcmp( string1, string2));
  strcpy(string1, "NewFile.ooo");
  strcpy(string2, "NewFile.oo");
  printf("Return Value is : %d\n", strcmp( string1, string2));
  strcpy(string1, "NewFile.oo");
  strcpy(string2, "NewFile.oo");
  printf("Return Value is : %d\n", strcmp( string1, string2));
  return 0;
}

Output Will Be :

Output

Return Value is : -111
Return Value is : 111
Return Value is : 0


« Previous
Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!