So in this program im supposed to be reading characters from a file. So i opened the file and read them into an array,
this is the assignment
Write a C++ program that reads in a text file ( called data8.txt), and prints the file to the screen the text with all extra blanks removed (that is, if there are 2 or more blanks in a row, replace them by a single blank) and changes ALL letters to UPPERCASE letters.
WATCH THAT YOU DON'T DELETE CARRIAGE RETURNS and tabs. Whitespace includes tabs and carriage returns as well as blanks…so you only want to get rid of extra blank characters.
I tried using another while loop to identify the blank spaces, something along the lines of
while(array[count]==" ")&&(array[count+1]==" "
but you cannot test to see if it is equal to a character.
any ideas? i would appreciate any help
i had tried something like that initially and it was giving me an error that i couldnt set the character variable to a blank, maybe i made some other error, but i will try it out and let you know if it works,
ok just tried it and it worked, im not sure i understand what you did with the bool blastspace, its initialized to false, but then defaults to false in the if else statement
That's because it's in a while loop. Essentially, that if statement is done over and over and over, and whether blastspace is true or false is evaluated repeatedly.
blastspace is used to know if we have continued spaces. It is set to true if any space is found and so for any next consecutive spaces, nothing will happen, loop will just continue.
as soon the spaces ends, blastspace will be set to false and normal scenario will happen. try debugging to know whats going on.