I'm trying to get my first while loop to quit on blank spaces.... I have tried for awhile but am officially stuck.
CODE: http://pastebin.com/d21f81f7c
I'm trying to get my first while loop to quit on blank spaces.... I have tried for awhile but am officially stuck.
CODE: http://pastebin.com/d21f81f7c
guess this thingy '/b' is called a multibyte char literal.Code:while(counter < 20 && dataIn != '/b')
it's not what you want
try
KurtCode:while(counter < 20 && dataIn != '\b')
opps! ... but I have tried a lot of different ways (including \b) still no luck...
And a blank space is ' ', not '\b' (which is backspace, maybe?)
it's telling me that != doesn't take type char... but I have to use char
Kurt, that helped me get on a new track... thanks.
But why does this not do it then?
while(counter < 20 && (song[n].title[counter] != ' '))
dataIn.get(song[n].title[counter++]);
Guess it does what it should do. But you didn't terminate the string.
try
KurtCode:while(counter < 20 && (song[n].title[counter] != ' ')) dataIn.get(song[n].title[counter++]); song[n].title[counter] = 0;
none of that worked.... even if I put:
while(counter < 20 && (song[n].title[12] != ' '))
dataIn.get(song[n].title[counter++]);
where I know there is a blank it does nothing... ?
I just realized in the file (song.txt) things are separated not by spaces but by tabs...
You could use getline, and use the tab character ('\t') as a delimiter.
Another thing is using char arrays. Are you sure that none of the items in the file is longer than 19 characters? In any case, the code would be much more robust and easier to get right, if you used the C++ standard string class.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.