Quote:
Write a complete C++ program that will read a line of text at a time from the keyboard as a string. Your program will separate it into words for any of these 4 whitespace characters -- blank ' '; tab '\t'; return '\r'; and newline '\n' – and print each word. Upon receiving end of file, your program will terminate.
Use cin.getline() to read a whole line of input at a time (see both table 6-3 on page 218 and table 6-4 on page 219) as in this sample code fragment:
#define LINELEN 100
...
char buffer[LINELEN];
...
cin.getline(buffer, LINELEN);
No string functions are required, but you may use them if you wish. However, you may not use the function strtok() if you should happen across it. It is deprecated since it alters its string argument without warning. You can compare characters with == in an if or while statement, or use a switch statement for one char.
Your screen will resemble:
Enter string: test one line now
Word 1: test
Word 2: one
Word 3: line
Word 4: now
Enter string: ^Z
I think where my program is at now it will account for what the teacher wants to input. If I like type in Hello <TAB KEY> WORLD, is displays both words correctly. Does it appear that I am missing anything?