I have a file with 10 lines, and in each line there is, separated by spaces, a name, an id and an age. Problem is that when reading this file with fgets and sscanf, it returns me a seg fault when trying to read more than 2 lines.
typedef struct Person
{
char t;
long i;
float a;
} Person;
*arrPersons = (Person*)malloc(10 * sizeof(Person));
int assignInputPeople(Person **arrPersons, FILE *inputPeople)
{
int counter = 0;
char fileLine[344];
long ID;
float ageF;
while (fgets(fileLine, 344, inputPeople) != NULL)
{
sscanf(fileLine, "%s %s %s", arrPersons[counter]->name,&ID)
}
I created a pointer to pointer for my array so that I can modify it in other functions, like this one above.