home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / stnrgmax.pak / STRNGMAX.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  2KB  |  56 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  STRNGMAX.H                                                            */
  4. /*                                                                        */
  5. /*  Copyright (c) 1991, 1993 Borland International                        */
  6. /*  All Rights Reserved.                                                  */
  7. /*                                                                        */
  8. /*  String example file                                                   */
  9. /*                                                                        */
  10. /*------------------------------------------------------------------------*/
  11.  
  12. #if !defined( __CSTRING_H )
  13. #include <cstring.h>
  14. #endif  // __CSTRING_H
  15.  
  16. #ifndef __IOSTREAM_H
  17. #include <iostream.h>
  18. #endif
  19.  
  20. //
  21. // Determines the maximum string using the ASCII collating sequence to 
  22. // define rank.  A string is defined to be greater than another if the
  23. // ASCII values of its characters are greater than the values of the other
  24. // string.  For example,
  25. //
  26. // strngmax Alpha Beta Charlie
  27. //
  28. // would print Charlie to stdout and return 3.
  29. //
  30.  
  31. int main( int argc, char *argv[] )
  32. {
  33.     if( argc < 2 )
  34.         {
  35.         cerr << "Usage:  strngmax string1 [string2 ...]\n";
  36.         return 1;
  37.         }
  38.  
  39.     string TheGreatestString( argv[1] );
  40.     int PositionOfTheGreatestString = 1;
  41.     int NextArg = 2;
  42.  
  43.     while( NextArg < argc )
  44.         {
  45.         string ArgListString ( argv[NextArg++] );
  46.         if ( ArgListString > TheGreatestString )
  47.             {
  48.             TheGreatestString = ArgListString;
  49.             PositionOfTheGreatestString = NextArg - 1;
  50.             }
  51.         }
  52.  
  53.     cout << TheGreatestString << endl;
  54.     return PositionOfTheGreatestString;
  55. }
  56.