?
Solved

Reading in white space

Posted on 2003-02-19
3
Medium Priority
?
230 Views
Last Modified: 2010-04-01
I am having a problem reading in white space when taking characters off of a string...any suggestions?

This is what I have so far...

while(1)
{
symbol = array[ptr2][ptr];
while ( symbol == ' ' )

bla bla bla

Thanks for looking...
0
Comment
Question by:ArthurFonzareli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:burcarpat
ID: 7985538
what do you mean by whitespace?  cause, '' is probably not that; but ' ' is ( i.e. there must be an actual space there )  also, the question is not very clear and the code you wrote is, ummm, incorrect.  can you post more details and some actual, compiling code?
0
 
LVL 12

Accepted Solution

by:
Salte earned 400 total points
ID: 7986599
For one thing, C++ nor C nor any other language in the C family of languages have any construct like:

while (1) {
  ....code...
} while (test);

do { ... } while (test);

and

while (test) { ... }

are the two constructs that are in use.

Secondly '' is not a valid token, it is possible you write ' ' or meant to write ' ' but that is only testing for space. What about tab characters? They also count as space in most cases.

If you want to skip whitespace C++ has a mechanism for doing so:

ifstream file("file.txt");
file >> ws >> ... ;

The 'ws' there will tell file to skip any whitespace before next read. Most formatted reads will skip whitespace anyway but ws will also do it in the few cases where it otherwise wouldn't.

Unformatted read never skip whitespace but doing ws(file) or file >> ws; will then cause it to skip whitespace also if you do an unformatted read after.

Good luck with your program.

Alf
0
 

Author Comment

by:ArthurFonzareli
ID: 7988625
Thanks

You knew exactly what I meant...
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question