Thu Nov 13, 2008 2:24 pm
/* This program removes any indentation and blank lines from its input. */
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char inch; // Input character.
bool suppressing = true; // Currently suppressing leading space.
while(cin.get(inch)) {
/* At the end of a line, if we have suppressed up to this
point, squash the newline, too, to eliminate the whole
line. Otherwise, begin suppression for the next line. */
if(inch == '\n')
if(suppressing)
continue;
else
suppressing = true;
else
/* Not end-of-line. See if we are worrying about
suppressing spaces right now. */
if(suppressing)
/* We are suppressing spaces. If it's a space,
squash it; if not, we aren't suppressing
anymore. */
if(isspace(inch))
continue;
else
suppressing = false;
/* If we got here, this character should not be suppressed. */
cout << inch;
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.