![]() |
|
#1
|
|||
|
|||
Help reading from a file into a structure arrayHello. I am trying to read info from a file into an array of a created structure. After running the program on visual studio 2008, it gives me no syntax error but this dialog box appears "debug assertion failed". Can anyone look at my code and tell me the problem.. Thanks in advance.
CPP / C++ / C Code:
The content of the file is as follows: Code:
Last edited by admin : 29-Oct-2009 at 03:39.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
|||
|
|||
Re: Help reading from a file into a structure arrayYou are trying to read 4 students into an array that can only hold 3.
|
|
#3
|
|||
|
|||
Re: Help reading from a file into a structure arrayYou declare an array of three structs ant then you try to store data for more than three.
Try something like the following to see how it goes: CPP / C++ / C Code:
If you increase you dimension to more than four, it shouldn't crash the way that it did, but I'm thinking that you should see why your loop is not right. For example, I get the following: Code:
With four lines in the file, it goes through the loop five times. (The eof flag is not set until after it tries to read past the end of the file.) That topic (improper use of eof as a loop control) has been covered numerous times, but I know it's hard to believe that it simply doesn't work the way that you want it to without seeing it for yourself. If get past the crash (by increasing the size of the array) but you still can't find how to make the loop work properly, let us know, and maybe someone can give some more clues. Bottom line: Always (yes, always test the result of a read operation to see that the proper number of items was read! Regards, Dave |
|
#4
|
|||
|
|||
Re: Help reading from a file into a structure arrayThank You very much.. Works great after increasing the size of the array person[] by 1. I do understand well how reading the file works, thanks to your example.
|
|
#5
|
|||
|
|||
Re: Help reading from a file into a structure arrayQuote:
So did you change your loop so that it does not attempt to store five things from your four-line file? I mean, even if it happens not to actually crash the program, you need to read exactly what the file has. Neither more nor less. Regards, Dave |
|
#6
|
|||
|
|||
Re: Help reading from a file into a structure arrayexactly what i do.. works fine.. thx
|
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Power Calibration Error In Nero Fix (hopefully) | matt3678 | Computer Hardware Forum | 60 | 20-Aug-2009 06:04 |
| contents of .txt file into 2D array | anirudhroxrulz | C Programming Language | 4 | 10-Apr-2008 23:45 |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| After execution - Error cannot locate /Skin File? | WSCH | C++ Forum | 1 | 05-Mar-2005 21:03 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The