Click here to Skip to main content
15,922,584 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Renaming a project Pin
Andrew Walker5-Apr-04 3:17
Andrew Walker5-Apr-04 3:17 
GeneralRe: Renaming a project(EDITED) Pin
John M. Drescher5-Apr-04 5:41
John M. Drescher5-Apr-04 5:41 
GeneralRe: Renaming a project(EDITED BY ME) Pin
Trollslayer5-Apr-04 6:00
mentorTrollslayer5-Apr-04 6:00 
GeneralRe: Renaming a project(EDITED BY ME) Pin
John M. Drescher5-Apr-04 6:14
John M. Drescher5-Apr-04 6:14 
GeneralIPersistStorage::Load() for Embeded object of Word Creates .doc file in Temp Pin
anshumanshinde5-Apr-04 2:47
anshumanshinde5-Apr-04 2:47 
GeneralRe: IPersistStorage::Load() for Embeded object of Word Creates .doc file in Temp Pin
Mike Dimmick5-Apr-04 6:37
Mike Dimmick5-Apr-04 6:37 
Generalread a certain line from a text file Pin
dairiseky5-Apr-04 2:44
dairiseky5-Apr-04 2:44 
GeneralRe: read a certain line from a text file Pin
avenger_sb255-Apr-04 3:42
avenger_sb255-Apr-04 3:42 
YOU HAVE GOT A PROBLEM IN THE while LOOP.

I have stripped down ur while loop for simplicity;)

The Problem(step by step):
while (!GPSFile.eof()){<br />
GPSFile >> gpsx;<br />
GPSFile >> gpsy;<br />
}

In the first time it loops, x-value is copied into gpsx and y-value is copied into gpsy. BUT you havent reached end of file yet, SO the while loop is executed again and this time, the value of speed is copied into gspx (thats the ERROR!!!)
So erronous output is
2.8
4.87067e+006
SOLUTION
Solution 1:
while (!GPSFile.eof()){<br />
if (GPSFile.rdstate() == ios::failbit){cout<<"ERROR, \n";}<br />
GPSFile >> gpsx;<br />
GPSFile >> gpsy;<br />
break; //BREAK OUT SO THAT THE WHILE LOOP IS NOT EXECUTED AGAIN :rose:<br />
}//endwhile<br />
CataCoordX=gpsx;<br />
CataCoordY=gpsy;

Solution 2:
while (!GPSFile.eof()){<br />
if (GPSFile.rdstate() == ios::failbit){cout<<"ERROR, \n";}<br />
GPSFile >> gpsx;<br />
GPSFile >> gpsy;<br />
GPSFile >> gpspeed;//on lit //THIS WILL END READING THE FILE(reach EOF):rose:<br />
CataCoordX=gpsx;<br />
CataCoordY=gpsy;<br />
}//endwhile

PROBLEM SOLVED

Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs Smile | :)

...avenger
GeneralRe: read a certain line from a text file Pin
dairiseky5-Apr-04 4:01
dairiseky5-Apr-04 4:01 
GeneralRe: read a certain line from a text file Pin
avenger_sb255-Apr-04 4:46
avenger_sb255-Apr-04 4:46 
GeneralRe: read a certain line from a text file Pin
dairiseky5-Apr-04 5:18
dairiseky5-Apr-04 5:18 
GeneralRe: read a certain line from a text file Pin
avenger_sb255-Apr-04 7:10
avenger_sb255-Apr-04 7:10 
GeneralRe: read a certain line from a text file Pin
dairiseky5-Apr-04 8:02
dairiseky5-Apr-04 8:02 
GeneralRe: read a certain line from a text file Pin
avenger_sb255-Apr-04 8:51
avenger_sb255-Apr-04 8:51 
GeneralRe: read a certain line from a text file Pin
David Crow5-Apr-04 4:50
David Crow5-Apr-04 4:50 
GeneralRe: read a certain line from a text file Pin
dairiseky5-Apr-04 5:22
dairiseky5-Apr-04 5:22 
GeneralRe: read a certain line from a text file Pin
David Crow5-Apr-04 7:33
David Crow5-Apr-04 7:33 
GeneralRe: read a certain line from a text file Pin
Anonymous5-Apr-04 7:44
Anonymous5-Apr-04 7:44 
GeneralRe: read a certain line from a text file Pin
dairiseky5-Apr-04 7:48
dairiseky5-Apr-04 7:48 
GeneralRe: read a certain line from a text file Pin
dairiseky6-Apr-04 2:46
dairiseky6-Apr-04 2:46 
GeneralRe: read a certain line from a text file Pin
David Crow6-Apr-04 3:24
David Crow6-Apr-04 3:24 
GeneralDialog related question Pin
Imtiaz Murtaza5-Apr-04 2:16
Imtiaz Murtaza5-Apr-04 2:16 
GeneralRe: Dialog related question Pin
avenger_sb255-Apr-04 2:48
avenger_sb255-Apr-04 2:48 
GeneralRe: Dialog related question Pin
David Crow5-Apr-04 4:52
David Crow5-Apr-04 4:52 
GeneralC++ Pin
cberam5-Apr-04 2:05
cberam5-Apr-04 2:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.