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.

Recommended Answers

All 3 Replies

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.

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.

>>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.