home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_07 / 1107107b < prev    next >
Text File  |  1993-05-04  |  542b  |  28 lines

  1. // lwc.cpp: Display count of lines and words
  2. #include <iostream.h>
  3. #include <strstream.h>
  4. #include <stddef.h>
  5.  
  6. main()
  7. {
  8.     const size_t BUFSIZ = 128;
  9.     char s[BUFSIZ];
  10.     size_t lc = 0, wc = 0;
  11.     
  12.     while (cin.getline(s,BUFSIZ))
  13.     {
  14.         ++lc;
  15.         istrstream line(s);
  16.         char word[BUFSIZ];
  17.         while (line >> word)
  18.             ++wc;
  19.     }
  20.     
  21.     cout << "Lines: " << lc << ", words: " << wc << endl;
  22.     return 0;
  23. }
  24.  
  25. // Output from the statement "lwc < lwc.cpp"
  26. // Lines: 24, words: 63
  27.  
  28.