strcmp()                 Compare Two Strings, Case Sensitive
 
 #include   <string.h>                   Required for declarations only
 
 int        strcmp(string1,string2);
 char       *string1;                    First string
 char       *string2;                    Second string
 
    strcmp() compares 'string1' and 'string2' lexicographically ('a' is
    less than 'b', 'b' is equal to 'b', 'c' is greater than 'b', and 'A'
    is less than 'a').
 
    Returns:    A value indicating the relationship between the two
                strings:
 
                      Comparison          Returned
 
                'string1' <  'string2'      < 0.
                'string1' == 'string2'        0
                'string1' >  'string2'      > 0.
 
      Notes:    strcmp() expects to operate on null-terminated strings.
                No overflow checking is done when strings are copied or
                appended.
 
  -------------------------------- Example ---------------------------------
 
    This example finds the string that sorts first (alphabetically) and
    prints the strings accordingly:
 
         #include <string.h>
         #include <stdio.h>               /* for printf */
 
         char str1[20], str2[20];
         int order;
 
         main()
         {
               strcpy(str1,"alligator");
               strcpy(str2,"albatross");
               if ((order = strcmp(str1,str2)) <= 0)
                  printf("1. %s     2. %s  \n", str1,str2);
               else
                  printf("1.  %s     2. %s  \n",str2,str1);
         }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster