I have an assignment where I have to xfer information from a .txt file into arrays but when I attempt to do this I get a really bad error message that states "An unhandled exception of type 'System.AccessViolationException' occurred in Project 6.exe" Can someone please check my code and see whats causing this issue? Btw the content in the .txt file looks like this:
A.Smith 89
T.Philip 95
S.LOng 76
Sometimes my compiler doesn't "compile" correctly and I have to make a new project. If everything is working correctly for others you may try just copying your code into a fresh project.
After running this code I get a 76...perhaps I should create two separate arrays...one for name and another for score?? and If so how would I go about cherry picking the content in the text file for each specific array?
perhaps I should create two separate arrays...one for name and another for score?
That's one approach. Another would be to define a struct to hold all the data for a single row.
I'm always wary of solutions which assume the file will contain a specific number of lines (in this case 3), I'd prefer more generalised code which could cope with a file containing more or fewer lines. Below, I've used a fixed size array to hold a maximum of 20 lines, and the actual number of rows read are counted during the input loop.