473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

EOF() not recognized in a long file

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.
Jul 22 '05 #1
2 1600

"Jackie" <ja**********@corr.ca.gov> wrote in message
news:47**************************@posting.google.c 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
Jul 22 '05 #2
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.

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Baz | last post by:
Hi All, I have a problem with the above command. I have a file which is approximately 7000 lines long. I want to parse that file, extract any lines containing a certain string, and add that line...
1
by: Robert | last post by:
On some connections only from some computers/network setups I get this error: Traceback (most recent call last): File "<interactive input>", line 1, in ? File...
76
by: Alan Connor | last post by:
-- Alan C this post ends with w q From K&R: #include <stdio.h> main()
7
by: hugo27 | last post by:
obrhy8 June 18, 2004 Most compilers define EOF as -1. I'm just putting my toes in the water with a student's model named Miracle C. The ..h documentation of this compiler does state that when...
20
by: Xenos | last post by:
Can anyone tell me what the standard says about using fseek (on a binary file) to seek past the end-of-file? I can't find anything in my (draft) copy of the standard, nor in the FAQ. Thanks
20
by: TTroy | last post by:
Hello, I have found some peculiar behaviour in the fgets runtime library function for my compiler/OS/platform (Dev C++/XP/P4) - making a C console program (which runs in a CMD.exe shell). The...
2
by: Dmitry Anikin | last post by:
I want to read stdin in chunks of fixed size until EOF I want to be able (also) to supply data interactively in console window and then to hit Ctrl+Z when finished So what I do is: while True:...
18
by: Seeker | last post by:
I essentially copied this program from K&R: #include <stdio.h> #include <stdlib.h> int main() { int c;
15
by: waltbrad | last post by:
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In chapter 6 he gives an exercise that reads from a file. The list is thus: 4 Sam Stone 2000 Freida Flass 100500 Tammy...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.