Hi, I have this program - im pretty sure its coded correctly, and i have a datafile - basically its just a few lines of numbers. Anyways im not sure about the procedure on how to open/read datafiles with the example below.
Basically my program is about a mayors race with 4 candidates. I allready programed everything to count all the votes, percentage of votes, if a candidate has 50% of the vote he wins and it declares he/she the winner, if nobody gets 50% then it declares a runoff. Anyways im just having a problem opening and reading the datafile with all the vote figures. All the work i put into the code is useless if i cant read the datafile inputs!
For example: datafile.txt (4 candidates = 4 columns of votes)
192 48 206 37
147 90 312 21
186 12 121 38
114 21 408 39
267 13 382 29
I use olympus to compile and run my program.
gcc mayorrace.c (compiles the program - compiles fine)
a.out -datafile.txt (runs the compiled program also points to the datafile - basically it just sits there and does nothing - i push escape and then it outputs alot of 0's instead of the actual datafile votes)
What do i need to do? Thanks for your time Any tips would be greatly appreciated.Code:Precinct Candidate A Candidate B Candidate C Candidate D 1 0 0 0 134396 2 0 0 0 -12687724 3 0 0 0 0 4 0 0 -4260984 0 5 0 0 224592 0 Total 0 0 -4036392 -12553328 Percent 0 0 24 76
The last program i had that used a datafile i used this line:
FILE *fpr = fopen("datafile.txt", "r");
but thats not working very well this time, either that or i dont know where to put it...