|
-
February 9th, 2003, 12:40 AM
#1
reading files in using ifstream
I am trying to read a file in using ifstream.
The file is comprized of three fields
Name
Age
Address
the file looks like this:
April,Joe
21
126 Freelane, Yourtown, State 88990
Matthews,Jocob
19
3930 4th Blvd, Yourcity, NJ 88710
Garfield,Kitty
24
36 Jon Havey Court, Middle, MO 66222
Lake,Bill
male
21 Ritts, Commack, NY 13231
I read it in like so:
while(ifile.getline(strLine, MAXLINE, '\n'))
{
if(strLine[0] != NULL){
counter++;
if(counter == 1){
strcpy(temp_person.strName, strLine);
} else if (counter == 2){
strcpy(buf, strLine);
} else if (counter == 3){
strcpy(temp_person.strAddress, strLine);
counter = 0;
}
}
}
On the last record I get an GPF (access violation). I remember that you are supposed to read a line in first to get the EOF to work. Does any one remember this.
Thanks in advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|