Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Reading in white space

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
ArthurFonzareli
Asked:
ArthurFonzareli
1 Solution
 
burcarpatCommented:
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
 
SalteCommented:
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
 
ArthurFonzareliAuthor Commented:
Thanks

You knew exactly what I meant...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now