Total members 11889 |It is currently Thu Mar 28, 2024 9:39 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





removes any indentation and blank lines from strings input using C++
cpp 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.



_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Remove Indentation
 remove page title     -  
 Remove all the vowels from a string     -  
 Remove a portion of the array and replace it with something     -  
 Add and Remove CSS classes to html tag dynamically     -  
 Remove border of the linked image     -  
 Remove ordered list numbers     -  
 Remove HTML element or Delete its content     -  
 How to remove special characters from a string in Java?     -  
 How to delete/remove images from excel 2007 using POI.     -  
 Remove default window icon from JFrame     -  



Topic Tags

C++ Strings
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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