Like I said there is nothing in the code that is causing it to not work. How are you executing it? Is it just running a quick popup window and then disappears?
Regarding your logic, if each numerical value represents a candidate then why not do something like this:
Code:
#include <stdio.h>
int main(void)
{
int candidates[5] = {0};
int i;
FILE * fp;
/* note this has no 50 size limit as before.. */
if (fp = fopen("votes.txt", "r")) {
while (fscanf(fp, "%d", &i) != EOF) {
/* invalid vote (out of range */
if (i < 0 || i > 5) {
fprintf(stderr, "Invalid Candidate: %d!\n", i);
continue;
}
/* otherwise we got a valid vote, count it */
++candidates[i];
}
fclose(fp);
}
for (i = 0; i < 5; ++i)
printf("Candidate #%d had %d votes\n", i, candidates[i]);
return 0;
}