/* emptyline.cpp - define function that recognizes if
	current line is null or contains non white characters.
	Use it to read sequence of names printing out their lengths.
 */

#include <iostream>
#include <string>
using namespace std;

// it returns true if next input line
// contains no non space characters
// otherwise returns false and leaves line unchanged
bool emptystring(void)
{
	char c;
	cin.get(c);
	while ( (c != '\n') && isspace(c) )
		cin.get(c);
	if (c != '\n')
		cin.putback(c);
	return 	(c == '\n');//i.e., true if c is '\n', false otherwise
}

int main()
{
	for ( ; ; ) {
		string name;
		cout << "Enter a name [ null to end]: ";
		if (emptystring()) break;
		cin >> name; //this does not consume the '\n' at end of line
		cin.ignore(256, '\n'); //ignore will consume the '\n'
		cout << name + " is of length " << name.length() << endl;
	}

	return 0;
}
