source: doc/theses/mike_brooks_MMath/word.cfa@ bd72f517

Last change on this file since bd72f517 was 38e17b0, checked in by Peter A. Buhr <pabuhr@…>, 5 months ago

add string example to extract words from line

  • Property mode set to 100644
File size: 734 bytes
Line 
1#include <string.hfa>
2#include <fstream.hfa>
3
4int main() {
5 string line;
6 charclass alpha{ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" };
7 size_t i;
8
9 try {
10 for ( ;; ) {
11 sin | getline( line );
12 for ( ;; ) { // scan words off line
13 size_t posn = exclude( line, alpha ); // find position of 1st alphabetic character
14 if ( posn == len( line ) ) break; // any characters left ?
15 line = line( posn ); // remove leading whitespace
16 posn = include( line, alpha ); // find position of 1st non-alphabetic character
17 sout | line( 0, posn ); // extract word from start of line
18 line = line( posn ); // delete word from line
19 } // for
20 } // for
21 } catch( end_of_file * ) {}
22}
Note: See TracBrowser for help on using the repository browser.