Strncmp() function compares up to a given number, n, of characters of the two strings. - C String

C examples for String:Compare

Description

Strncmp() function compares up to a given number, n, of characters of the two strings.

Demo Code

#include <stdio.h> 
#include <string.h> 
int main(void) {

   char str1[] = "The quick brown fox";
   char str2[] = "The quick black fox";
   if (strncmp(str1, str2, 10) <= 0)
      printf("\n%s\n%s", str1, str2);
   else//  w w w .  j  ava2s  . c om
      printf("\n%s\n%s", str2, str1);
   return 0;
}

Result


Related Tutorials