/*

This is some sample C++ code that shows how to skip leading white
space, embedded white space, and trailing white space on input.

There is some sample input at the end of the file, followed by
the output the program produces for that input.

  */

#include <iostream.h>
#include <iomanip.h>
#include <string>


void skipWhiteOnLine()
{
  char curCh ;

     /* 

        Keep checking the next character and read all blanks or
	tabs.  Stop before the first character that is not a
	blank or tab.  If the only whitespace on the line is
	blanks or tabs, then this function will stop either just
	before a "black space" character, or just before the end
	of a line.  If you want it to skip other kinds of
	characters, you have to add tests for those characters to
	the while condition.

     */

  while ((cin.peek()==' ') || (cin.peek()=='\t'))
         cin.get(curCh) ;
}
/*
    
Main is a function that goes through the input and extracts all
extraneous white space -- blank lines, extra embedded blanks
between "words," and all leading and trailing whitespace.

Each non-blank line on the input is echoed, except that there is
no whitespace other than a single blank that the program inserts
between each pair of words on a line.

*/
int main()
{
  string str ;
  char curCh ;

   /* Begin by using the ws manipulator to skip to the first
      black space character in the first non-blank line of the
      input, or end of file (end of input) if there is no black
      space. */

  cin >> ws ;  

     /* Now enter a nested loop.  Each time through the body of
        the outer loop one non-blank line is processed. */

  while (!cin.eof())   /* While not at end of file */
  {

          /* If we have arrived at this part of the code, then it
	     is because we have moved down to a point where there
	     is a blackspace character to be read next. So get
	     the first string on the current line, read and echo
	     */

      cin >> str ;
      cout << str ;

           /* get past white space after string we just read, but
	      don't skip past the end of the current line. */

      skipWhiteOnLine() ; 

          /* This inner loop gets the rest of the strings on the
	     current line, if there are any more.  For each new
	     string on this line, it prints one blank as a
	     separator and then the string.  It pulls out all the
	     other white space that might occur between strings. */
      do
      { 
           /* if there is another string on the line, 
              print one separating blank, read and echo the
              the string.  */
        if (cin.peek() != '\n')  /* if we are not at end of line */
        {
           cout << ' ' ;
           cin >> str ;
           cout << str ;

               /* move to start of next string, or end of line. */
           skipWhiteOnLine() ; 
        }
      }
      while (cin.peek() != '\n') ; /* Stop if end of line is next. */

       /* When we get here in the code, it is because we have
	  reached the end of the current non-blank line.  so get
	  and echo the newline character at the end of the line. */

    cin.get(curCh) ;  
    cout << endl ; /* write the newline character  */
      
       /* Now we are ready to search for the start of the next
	  non-blank line, or move to the end of the input, if
	  there are no more blackspace characters. */

    cin >> ws ;
  }

  return 0 ;
}
/* INPUT:




    This   is some    weird 	input with     stuff     
 that is white space      mixed in to the            lines.


How     in heck		can we     compact it all out?
I        guess there     must be            some    way?




OUTPUT:

This is some weird input with stuff
that is white space mixed in to the lines.
How in heck can we compact it all out?
I guess there must be some way?

*/
