I am trying to write a C program to read a CSV file and calculate something and printing a line to the screen. However, the values I am storing in my array do not seem to match up with my input file.
For 1,2,2,3
I get an average of 50.0000000 printed to the screen. Can anyone offer some advice? Thank you.
#include <stdio.h>
#include <string.h>
int main (void) {
...
fclose(input);
}
*p
is a character, so you are putting ASCII codes intodata
. You want the values these represent, or you can (which your later use ofatof
suggests) declaredata
to be an array of strings.