EOF() not recognized in a long file 
July 22nd, 2005, 03:05 PM
| | | |
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?
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;
while (!existfile.eof())
{
memset(&Fp, 0, sizeof(struct FELON_PROFILE));
exist_count++;
existfile >> Fp.cdcno >>Fp.ethnic >>Fp.age[color=blue][color=green]
>> 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][/color]
cout<<Fp.cdcno<<" "<<exist_count<<endl;
logfile<<Fp.cdcno<<" "<<exist_count<<endl;
}
existfile.close();
cout <<"Existing Felons -- "<<exist_count<<" processed"<<endl;
return;
}
********** sample data ***********************;
baseyymm = 200309
A32262 BLA 862 0 0 1 L 203 387 0 1 KER 1 -582 A
A X
A32914 AMI 885 0 0 1 L 300 430 0 2 RIV 1 -580 A
A X
A40189 BLA 841 0 0 1 L 300 468 2 2 SAC 1 -559 A
A X
A40675 WHI 846 0 0 1 L 268 427 1 1 LA 1 -558 A
A X
A43907 BLA 804 1 3 4 L 1022 1022 0 3 ALA 33 -185 B
B ALA
A44223 HIS 844 0 0 1 L 360 310 1 1 SCL 13 -129 S
A LA
A44862 WHI 735 0 0 1 L 286 534 0 4 SCL 1 -548 A
A X
A49491 WHI 771 0 0 1 L 295 405 0 1 MON 1 -538 A
A X
A52525 MEX 782 0 0 1 L 354 513 4 2 SAC 1 -533 A
A X
A53475 MEX 745 0 1 2 L 167 358 0 2 FRE 6 -283 B
B X
A53751 WHI 968 0 0 1 L 84 360 0 3 HUM 1 -531 A
A X
A54826 BLA 872 0 3 2 D 712 360 1 9 LA 5 -270 B
B X
A55612 WHI 811 0 3 2 L 268 293 0 2 ALA 5 -290 B
B X
A57622 WHI 841 0 0 1 L 219 360 0 1 LA 1 -523 A
A X
A57897 WHI 763 0 7 2 D 154 111 0 3 LA 22 -118 N
B LA
A59330 MEX 762 0 0 1 W 354 726 0 8 SBD 1 -520 A
A X
A59872 WHI 758 0 0 1 L 297 361 0 1 ORA 1 -519 A
A X
.... + 100,000 additional records. | 
July 22nd, 2005, 03:05 PM
| | | | re: EOF() not recognized in a long file
"Jackie" <jack.leonard@corr.ca.gov> wrote in message
news:4731e46c.0406221314.4341dd20@posting.google.c om...[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]
Its probably because you are hitting a read error (probably some bad format
in your file). Your code does not test for this, which is why it loops for
ever.
Here how you should do it
if (existfile>>dummy1>>dummy2>>byymm)
{
...
while (existfile >> Fp.cdcno >>Fp.ethnic >>Fp.age[color=blue][color=green]
>> 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][/color]
{
...
}
...
}
if (existfile.eof())
{
// got to end of file
}
else
{
// some other error
}
john | 
July 22nd, 2005, 03:05 PM
| | | | 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] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|