I have a .txt file that contains the data on a moving object in the following format
mass size velocity(x) velocity(y) velocity(z) etc
In addition, this file contains some background information denoted by a character, so
M 1000
C 500
I've been trying to write code that reads through and sorts the data according to what is (so M is stored in one variable, C in another, and the data for the object stored in its correct arrays). Currently, my code segmentation faults when I compile it. I've tried re-writing it with fgets, fscanf, gets and in every other way I can, but nothing is working.
while(fgets(data, 50, file))
{
if (data[0] == "M")
{
M = data[1];
}
else
{
fscanf(data,
"%lf %lf %lf %lf %lf",
obj_stat[0],
obj_stat[1],
obj_stat[2],
obj_stat[3],
obj_stat[4],
obj_stat[5]);
}
}
int fclose(univ);