int main( int argc, char** argv) {
FILE *inFilePtr = fopen(*(argv + 1), "r");
char *rawdata = malloc(sizeof(char) * 100);
float *ary = malloc(sizeof(float) * 50);
int counter = 0;
float averageAns;
int count = 0;
while (count < 1 ){
//fgets(rawdata, 50, inFilePtr); //I have tried both
fscanf(inFilePtr, "%s", rawdata);
*(ary + counter) = atof(strtok(rawdata, ","));
counter++;
*(ary + counter ) = atof(strtok(rawdata, NULL));
counter++;
*(ary + counter) = atof(strtok(rawdata, NULL));
counter++;
count++;
}
I cannot for the life of me figure out why I keep getting a seg fault. It will seg fault even without the loop (the count < 1 was just to see if I could make it through once).
It will not work with fgets(), fscanf(). It seg faults when I change the stream in fgets to (stdin), and I mention this because I assumed the file * was the issue, but now I do not think it is. I have made the delimiter in my data file " " and ",".
If anyone know's what I did wrong, I would appreciate it.
ary[counter++] = atof(strtok(rawdata, NULL));
? – Aniket Inge