| re: EOF() not recognized in a long file
Jackie wrote:
[color=blue]
> EOF function is ignored in the following code!
> I am unable to read the file with the length of 20,000kb completely.
> After reading 7,000kb, after which the program continues execution
> indefinitely. It reads the first 1500 records (7,000kb) correctly,
> then structure elements are assigned blanks while the execution
> continues indefinitely.
> Is there a finite file size allowed for reading, or in using EOF()
> function?[/color]
It's a FAQ, but...
[color=blue]
> MS Visual C++ (6.0), on Windows 2000 (or XP)
>
> ****** c++ code *************************;
> #include <iostream.h>
> #include <fstream.h>
> #include <string.h>
> typedef struct FELON_PROFILE
> {
> char cdcno[8];
> char ethnic[4];
> int age;
> int priorser;
> int priorvio;
> int tcid;
> char sen_type;
> int net_term;
> int finalest;
> int cur_ser;
> int cur_vio;
> char in_cnty[4];
> int iseqno;
> int month;
> char loc;
> char rstat;
> char parcnty[4];
> char sv_flag;
> } PROFILE;
>
> ifstream existfile;
> ofstream logfile;
> PROFILE Fp;
>
> void main(void)
> {
> existfile.open("D:\\SIMMODEL\\INPROG\\MALE\\STARTP OP.TXT");
> logfile.open("D:\\SIMMODEL\\PROJECTS\\MINAKO\\LOGF ILE.TXT");
> int exist_count = 0;
> char dummy1[20], dummy2, byymm[7];
> existfile>>dummy1>>dummy2>>byymm;[/color]
replace these lines[color=blue]
> while (!existfile.eof())
> {
> memset(&Fp, 0, sizeof(struct FELON_PROFILE));
> exist_count++;
> existfile >> Fp.cdcno >>Fp.ethnic >>Fp.age
> >> Fp.priorser >>Fp.priorvio >>Fp.tcid
> >> Fp.sen_type >>Fp.net_term >>Fp.finalest >>Fp.cur_ser
> >> Fp.cur_vio >>Fp.in_cnty >>Fp.iseqno
> >> Fp.month >>Fp.loc >>Fp.rstat
> >> Fp.parcnty ;[/color]
with:
while (existfile >> Fp.cdcno >> ..... >> Fp.parcnty)
{
exist_count++;[color=blue]
> cout<<Fp.cdcno<<" "<<exist_count<<endl;
> logfile<<Fp.cdcno<<" "<<exist_count<<endl;
> }
> existfile.close();
> cout <<"Existing Felons -- "<<exist_count<<" processed"<<endl;
> return;
> }
>[/color]
[color=blue]
> ... + 100,000 additional records.[/color] |