Proofreading

hey i got a program that takes a text file outputted by a different program and reads it line by line and reformas it for another program.. basicly it allow the user to use the two programs one after another... neway. I got theformatting part perfect the problem is when i tried to make the program not just do the first line but every line all the way down the page it doesnt do anything.... I figure I prolly used the EOF command wrong and was looking for some proofreading..... here is my code... itsacctually somewhere long the lines of 118 l,ines but i figure i only need to paste the part where i read and write files to the text docs.
[code]
ifstream contents ("q2.txt");
ofstream examplefile ("example.txt");
while (! contents.eof() )
{
contents.getline (currentline,59);
worker = currentline;
ssnum[0] = worker[0];
ssnum[1] = worker[1];

...

finline[43]='3';
finline[44]='8';
finline[45]='0';
finline[46]='3';
examplefile << finline <<endl;
}
examplefile.close();
contents.close();
[/code]
any help would be nice Finline is the char array i want outputted on to the example.txt and q2.txt is the unformatted file... thanks in advance
[Size=5][blue]J[/blue][/size][size=3][red]eripedo[/red][/size]
[code]If Userclue > 0 then
msgbox("Woohoo that Makes one")
end if[/code]
So... How long do you think you'll be waiting?

Comments

  • EOF isn't detected until an attempt to read encounters it. You shouldn't be testing for EOF, you should be testing for getline to fail. Change this:
    [code=ffffff]
    [color=000000][b]while[/b][/color] (! contents.eof() )
    {
    contents.getline (currentline,[color=bb0000]59[/color]);
    ...
    [/code]To this:

    [code=ffffff]
    [color=000000][b]while[/b][/color] (contents.getline(currentline, [color=bb0000]59[/color]))
    {
    ...
    [/code]


  • no good it doesn't lock up ne more but it doesn't do anything either.
    [Size=5][blue]J[/blue][/size][size=3][red]eripedo[/red][/size]
    [code]If Userclue > 0 then
    msgbox("Woohoo that Makes one")
    end if[/code]
    So... How long do you think you'll be waiting?

  • : no good it doesn't lock up ne more but it doesn't do anything either.

    Well, this could be broken as well:
    [code=ffffff]
    finline[[color=bb0000]45[/color]]=[color=bb0000]'0'[/color];
    finline[[color=bb0000]46[/color]]=[color=bb0000]'3'[/color];
    examplefile << finline <<endl;
    [/code]Unless you set finline[47] to 0 somewhere else in the code, there is no null-terminator for that string.

  • I dont undestand what u mean the way the program works is it reformats the current data on that line.... and then sticks a series of 9 numbers at the end of that data. that 0 is onte of the nine numbers im using in character form.
    [Size=5][blue]J[/blue][/size][size=3][red]eripedo[/red][/size]
    [code]If Userclue > 0 then
    msgbox("Woohoo that Makes one")
    end if[/code]
    So... How long do you think you'll be waiting?

  • : I dont undestand what u mean the way the program works is it
    : reformats the current data on that line.... and then sticks a
    : series of 9 numbers at the end of that data. that 0 is onte of
    : the nine numbers im using in character form.

    You are using '0', which is represented by the number 48 in ASCII.
    [code=ffffff]
    printf([color=bb0000]"[/color][color=907050]%d[/color][color=907050]
    [/color][color=bb0000]"[/color], ([color=000080]int[/color]) [color=bb0000]'0'[/color]); [color=80a0b0][italic]// 48[/italic][/color]
    [/code]C strings are [italic]null-terminated[/italic] character arrays. The last character [italic]has[/italic] to be the null-character ('', or ASCII 0) or C routines will have no idea where the string ends. They will continue reading past the end of your string until they find a 0 byte somewhere in RAM and stop.

  • Correct me if im wrong... which i problably am... but since the code im using works perfectly up to the point that i put in the loop to make it do the whole doc.... wouldn't that mean that that it doesn't seem to get confused by that zero?

    just wondering... i understand what you mean but id rather avoid changing the coding if i dnt have to because it took me so long to get it this far.mind you if i'm wrong and that zero is the reason the loop is failing ill change it out.
    [Size=5][blue]J[/blue][/size][size=3][red]eripedo[/red][/size]
    [code]If Userclue > 0 then
    msgbox("Woohoo that Makes one")
    end if[/code]
    So... How long do you think you'll be waiting?

  • : Correct me if im wrong... which i problably am... but since the
    : code im using works perfectly up to the point that i put in the
    : loop to make it do the whole doc.... wouldn't that mean that that
    : it doesn't seem to get confused by that zero?

    Um, it's not getting confused by a 0.

    : just wondering... i understand what you mean but id rather avoid
    : changing the coding if i dnt have to because it took me so long to
    : get it this far.mind you if i'm wrong and that zero is the reason
    : the loop is failing ill change it out.

    That zero isn't hurting anything.

    Never mind.

  • lol darn ok im completely confused and disoriented...... but still no answer to my problem......
    [Size=5][blue]J[/blue][/size][size=3][red]eripedo[/red][/size]
    [code]If Userclue > 0 then
    msgbox("Woohoo that Makes one")
    end if[/code]
    So... How long do you think you'll be waiting?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories