Reading csv file in C, strtok not returning what I am expecting?

348 Views Asked by At

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);
}
1

There are 1 best solutions below

0
On BEST ANSWER

*p is a character, so you are putting ASCII codes into data. You want the values these represent, or you can (which your later use of atof suggests) declare data to be an array of strings.