Hello. What i'm trying to do is simple and I know that I could just get the answer offline. However, I wanted to finish this one myself, so if someone could fix what I believe to be a small error I would appreciate it.
I am simply trying to read a string from an input file and remove spaces such that there is only one space in between words, where in the input file there can be multiple spaces in between words. As of now I open the file and it removes all of the spaces. I will explain my algorithm in a second. Here is what I have:
The input file simply contains text, which reads:
This is the input file for Programming Project 6 on p. 366.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
ifstream in_stream;
in_stream.open("proj-8.dat");
char character;
character=false;
do{
in_stream.get(character);
if(character != ' '){
cout << character;
character=false;
}
else if(character==false)
{
cout << character;
character==true;
in_stream.get(character);
}
} while (! in_stream.eof());
in_stream.close();
}
As it stands what i'm trying to do is to set the variable character to false. If the first character is a letter (i.e. not a space), then it will print that character and then reset character to false. If it is a space it will print it and be set to true, so that the next time through the loop if it is another space neither condition will be satisfied and nothing will happen. Like I said, at this point it is just removing all of the spaces. It's also giving me a square at the end after my period...that I dont get.
this is currently my output:
ThisistheinputfileforProgrammingProject6onp.366. <--then there's a square right here.
Thank you in advance for the help! People here have been very friendly so far.