Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>strcmp() compare two strings, case sensitive</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
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);
         }

See Also: strncmp() strcmpi()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson