Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > EOF() not recognized in a long file

Reply
Thread Tools

EOF() not recognized in a long file

 
 
Jackie
Guest
Posts: n/a
 
      06-22-2004
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
>> 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 ;

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.
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      06-22-2004

"Jackie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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?


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
>> 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)

{
...
}
...
}
if (existfile.eof())
{
// got to end of file
}
else
{
// some other error
}

john


 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      06-22-2004
Jackie wrote:

> 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?


It's a FAQ, but...


> 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;

replace these lines
> 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 ;

with:
while (existfile >> Fp.cdcno >> ..... >> Fp.parcnty)
{
exist_count++;
> cout<<Fp.cdcno<<" "<<exist_count<<endl;
> logfile<<Fp.cdcno<<" "<<exist_count<<endl;
> }
> existfile.close();
> cout <<"Existing Felons -- "<<exist_count<<" processed"<<endl;
> return;
> }
>


> ... + 100,000 additional records.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is long long int not as long as promised?? Oliver Graeser C++ 10 09-26-2008 11:41 AM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
long long and long Mathieu Dutour C Programming 4 07-24-2007 11:15 AM
unsigned long long int to long double Daniel Rudy C Programming 5 09-20-2005 02:37 AM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments