MY PROGRAM IS NOT OUTPUTTING ANYTHING ON THE OUTPUT FILE

Feb 11, 2012 at 7:42am
*****************************************************************************************************************************************************************************************************************
Last edited on Feb 11, 2012 at 2:47pm
Feb 11, 2012 at 8:40am
1
2
3
4
5
6
7
8
9
10
char next, space = ' ';
//...
     while(!infile.eof())
     {
        if(!isspace(space)) //false
        {
            getline(infile, line);
            outfile << line <<endl;
        }
     }
Feb 11, 2012 at 8:53am
Hi ne555, i don't understand what you are trying to say. can you elaborate a bit?
Last edited on Feb 11, 2012 at 8:53am
Feb 11, 2012 at 9:05am
The condition is always evaluated as false. You are asking if ' ' is an space.
Feb 11, 2012 at 9:17am
**************************************************************************************************************************************
Last edited on Feb 11, 2012 at 2:48pm
Feb 11, 2012 at 10:03am
That's fine, but look at what you are using as argument of the function.
¿when did the variable 'space' change its value?
Feb 11, 2012 at 10:09am
What do you propose would be a solution for my problem?
Feb 11, 2012 at 12:58pm
You have assigned a ' ' (space) to a variable called 'space'. And what you are doing here is isspace(space). The variable space ALWAYS has the value ' ' means isspace(space) will always be true and therefore
( !isspace(space) ) will ALWAYS be false.
Therefore I don't really get what you are trying to achieve with the code
1
2
3
4
5
if(!isspace(space))
{
     getline(infile, line);
     outfile << line <<endl;
}


Why don't you try this instead?
1
2
3
4
5
while(!infile.eof())
{
	getline(infile, line);
	outfile << line <<endl;
}


But I don't think it will solve
align it to the left margin and then output it on the file

What you have to do is to remove the white spaces from the string variable "line" before you output to the file.

1
2
3
getline(infile, line);
// Place your code to remove white spaces from "line"
outfile << line <<endl;
Topic archived. No new replies allowed.