EOF() not recognized in a long file

Discussion in 'C++' started by Jackie, Jun 22, 2004.

  1. Jackie

    Jackie Guest

    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\\STARTPOP.TXT");
    logfile.open("D:\\SIMMODEL\\PROJECTS\\MINAKO\\LOGFILE.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.
     
    Jackie, Jun 22, 2004
    #1
    1. Advertising

  2. "Jackie" <> wrote in message
    news:...
    > 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
     
    John Harrison, Jun 22, 2004
    #2
    1. Advertising

  3. Jackie

    red floyd Guest

    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\\STARTPOP.TXT");
    > logfile.open("D:\\SIMMODEL\\PROJECTS\\MINAKO\\LOGFILE.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.
     
    red floyd, Jun 22, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    750
    Eric Sosman
    Jul 8, 2003
  2. Kobu
    Replies:
    10
    Views:
    667
    Keith Thompson
    Mar 4, 2005
  3. SpreadTooThin

    ifstream eof not reporting eof?

    SpreadTooThin, Jun 13, 2007, in forum: C++
    Replies:
    10
    Views:
    722
    James Kanze
    Jun 15, 2007
  4. Oliver Graeser
    Replies:
    10
    Views:
    604
    Oliver Graeser
    Sep 26, 2008
  5. Jan Burse
    Replies:
    67
    Views:
    1,122
    Jan Burse
    Mar 14, 2012
Loading...

Share This Page