Results 1 to 3 of 3

Thread: File I/O -- c++

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    11

    Unhappy File I/O -- c++

    I have a file that has the following data:

    a12 (where a1 is supposed to be a variable called inclass and 2 means the number of records in the file)
    andrew1234567abcdefgh
    bingoa7654321asdasahd

    and a
    struct personal {
    char name[6];
    char number[7];
    char instring[8];
    };

    how should i go about reading the data into the struct using c++ statements?

  2. #2
    jim mcnamara
    Guest
    It depends on the data in the file.

    If the data is char WITHOUT null-terminated strings
    Code:
    FILE *fptr;
    BOOL ok;
    fptr = fopen("myfile.txt")
    ok = 0;
    while(1)
    {
       ok = (fgets( personal.name, 6, fptr ) == NULL);
       if (ok) 
       {
           break;
        }
       ok= (fgets(personal.number,7,fptr) == NULL);
       
       ok = (fgets(personal.instring,8,fptr) == NULL)
       // assume that all reocrds have all fields
       // otherwise you gotta check ok and break
    }

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    11
    but what if i got the '\n' to deal with?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width