0

what im trying to do is read in a data from a file into 4 different arrays then also read in the same data using array of structs. the assignment is to show that we know how to use both methods of reading in and sorting the data. i have 3 functions for the arrays (for reading in the arrays, sorting the arrays, then printing) and same for the struct. but when i go to call the array funtions they work then i call the 3 struct functions but they dont work. if i comment out all the array functions and leave just the struct calls it works perfectly. i just cant get it to call both the array functions and the struct functions right after each other.

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

When you read something from a file you can not direct it to two different places at the same time. Read the data into the array then either (1) copy the data from the array into the structure, or (2) after the entire file has been read into the array rewind the file back to the beginning and read it again into structures.

0

ya i tried using rewind but that didnt help. So what i did was make 2 different input file streams and used one to call all the array functions and the other to call all the struct functions then it worked fine.

0

>>ya i tried using rewind but that didnt help
Then you didn't do it right. If you are using fstreams then you also have to call the clear() method to clear the error (eof) condition flag.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.