home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch5 / strcmps.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  889b  |  39 lines

  1. /*                      strcmps.c
  2.  *
  3.  *   Synopsis  - Outputs the values returned by library 
  4.  *               function strcmp().
  5.  *
  6.  *   Objective - To investigate the return value from 
  7.  *               strcmp().
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. /* Constant Definitions */
  15. #define LGTH 80
  16.  
  17. int main( void )
  18. {
  19.      char string1[80];
  20.      char string2[80];
  21.      int result;
  22.  
  23.      printf( "Enter the first string: " );
  24.      fgets( string1, LGTH, stdin );
  25.      printf( "Enter the second string: " );
  26.      fgets( string2, LGTH, stdin );
  27.  
  28.      if ( ( result = strcmp( string1, string2 ) ) > 0 )
  29.           printf( "string1 > string2\n" );
  30.      else if ( result < 0 )
  31.           printf( "string1 < string2\n" );
  32.      else
  33.           printf( "string1 = string2\n" );
  34.     
  35.      printf( "result is %d\n", result );
  36.      return 0;
  37. }
  38.  
  39.