- #1
Cinimod
- 34
- 0
For some reason, the code I has compiles, but it just doesn't seem to do what it should. The code I have atm, involves opening a file of numbers, reading the numbers, and sorting them into groups.
Any ideas why it doesn't work. When I use another loop to print the values of groups to the screen, all the elements of the array are zero. which I think is rather odd.
Code:
int nmax; // This is the number of lines in the file
int i; // Index
float num; groups[15];
// File is opened - I know that's not where the error is
FILE *file;
file = fopen("log.txt", "r");
for(i=0; i<nmax; i++)
{
fscanf(file, "%f\n", &num);
switch((int)num)
{
case '0': groups[0]++; break;
case '1': groups[1]++; break;
/* etc... */
}
}
Any ideas why it doesn't work. When I use another loop to print the values of groups to the screen, all the elements of the array are zero. which I think is rather odd.