Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 9:09 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Remove Indentation
PostPosted: Thu Nov 13, 2008 2:24 pm 
Offline
Beginner
User avatar

Joined: Sun May 25, 2008 5:34 pm
Posts: 95
Has thanked: 2 time
Have thanks: 1 time

Code:
/* 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;
        }
}


It's also worth noting the way this program uses the continue directive. The loop test reads the next character, entering the loop if there is one. The character is then printed at the end of the loop. Since the continue statement transfers control directly to the loop test, it has the effect of skipping the output and proceeding to the next character.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Remove ordered list numbers
 Remove border of the linked image
 How to delete/remove images from excel 2007 using POI.
 remove space ,trim strings from left side ,right side ,both.
 is there any method to remove such watermark?
 remove page title
 Remove a portion of the array and replace it with something
 Remove default window icon from JFrame

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team