home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 2.ddi / CLASSEXM.ZIP / STRNGMAX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  2.2 KB  |  93 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3.  
  4. // Contents ----------------------------------------------------------------
  5. //
  6. //      main
  7. //
  8. // Description
  9. //
  10. //      Contains a simple example program for class String.
  11. //
  12. // End ---------------------------------------------------------------------
  13.  
  14. // Interface Dependencies ---------------------------------------------------
  15.  
  16. // None
  17.  
  18. // End Interface Dependencies ------------------------------------------------
  19.  
  20. // Implementation Dependencies ----------------------------------------------
  21.  
  22. #ifndef __IOSTREAM_H
  23. #include <iostream.h>
  24. #define __IOSTREAM_H
  25. #endif
  26.  
  27. #ifndef __STRNG_H
  28. #include <strng.h>
  29. #endif
  30.  
  31. // End Implementation Dependencies -------------------------------------------
  32.  
  33.  
  34. // Function //
  35.  
  36. int main( int argc, char *argv[] )
  37.  
  38. // Summary -----------------------------------------------------------------
  39. //
  40. //      Illustrates a use of the String class.  Displays the alphabetically
  41. //      last string out of the given command line and returns the position
  42. //      of that string.
  43. //
  44. //      Usage:  strngmax string1 [string2 ...]
  45. //
  46. // Parameters
  47. //
  48. //      argc
  49. //
  50. //      The number of arguments passed on the command line.  There must
  51. //      be at least 1 argument other than the command name.
  52. //
  53. //      argv
  54. //
  55. //      A vector of character strings which are the arguments to the
  56. //      command line.
  57. //
  58. // Return Value
  59. //
  60. //     maxPosition
  61. //
  62. //     The position on the command line of the last string.  Returns
  63. //     1 if an error occurs.
  64. //
  65. // End ---------------------------------------------------------------------
  66. {
  67.     if ( argc < 2 )
  68.     {
  69.         cerr << "Usage:  strngmax string1 [string2 ...]\n";
  70.         return 1;
  71.     }
  72.  
  73.     String theLargestString( argv[1] );
  74.     int    maxPosition = 1;
  75.     int nextArg = 2;
  76.  
  77.     while ( nextArg < argc )
  78.     {
  79.         String argListString ( argv[nextArg++] );
  80.         if ( argListString > theLargestString )
  81.         {
  82.             theLargestString = argListString;
  83.             maxPosition = nextArg - 1;
  84.         }
  85.     } // end while more arguments on the command line.
  86.  
  87.     cout << theLargestString << "\n";
  88.     return maxPosition;
  89. }
  90. // End Function main //
  91.  
  92.  
  93.