C strncmp function

« Previous

Synopsis:

Example

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

Description:

The strncmp function compares first n characters 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", strncmp( string1, string2, 4));
  strcpy(string1, "NewFile.ooo");
  strcpy(string2, "NewFile.oo");
  printf("Return Value is : %d\n", strncmp( string1, string2, 10));
  strcpy(string1, "NewFile.oo");
  strcpy(string2, "NewFile.oo");
  printf("Return Value is : %d\n", strncmp( string1, string2, 20));
  return 0;
}

Output Will Be :

Output

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


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

Your Query was successfully sent!