![]() |
|
#1
|
|||
|
|||
Help with reading data...getting garbage outputHello forum, I new here and to C++ so any help would be greatly appreciated.
I am working on a program using arrays of structures and am reading data from an infile. I thought I was reading the data in correctly but am getting garbage out put when trying to just print a screen cout check. Can any one point out what I am doing wrong. Thanks alot. D. sample goods.data- Boxing Gloves 1025 8 47 6.56 7.58 23.69 Red Trunks 2569 9 23 9.25 3.25 12.39 CPP / C++ / C Code:
Last edited by LuciWiz : 03-Dec-2005 at 08:42.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|||
|
#2
|
||||
|
||||
Re: Help with reading data...getting garbage outputHi mnkdrt,
Welcome to GIDForums. You are getting garbage because you should print only upto the lines read from the file. For example, consider that the MaxItems is 5. But your file contains only Two sets of data. So, if you print from 0 to 4, the first two values will be correct and the third, fourth and fifth values will be garbage. Just make a simple adjustment. Store the number of lines read in a variable count, and use it for printing. Like this: CPP / C++ / C Code:
And this statement may lead to errors: CPP / C++ / C Code:
Like this: CPP / C++ / C Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
|||
|
|||
Re: Help with reading data...getting garbage outputGreat and thanks for the help
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
| Need Help reading HEX data from a sensor | Moooey | C Programming Language | 4 | 09-Mar-2005 14:46 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
| using vector or array | oshiotse | C++ Forum | 4 | 16-Apr-2004 11:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The