I am using fscanf to read the entries of a file in a sequential way, and in each line of the file there is a variable number of entries;
imagine a 1-line file made in the following way:
where the "..." indicate that the following entries may not exist.
problem: prob_name prob_type ...
My original code that can read this line with a fixed/predefined number of entries is posted below, but I'd like some help in modifying it in such a way that it reads only the existing entries
I hope someone can help. It is for reading an input file full of a code.
thank you in advance
I though of something containing a WHILE, but I don't know how how to read the number of entries before reading them by using fscanf in this way.
#define PROB_ENTRIES 6
//Allocation of the array of pointers to chars
for(i=0; i<PROB_ENTRIES; i++)
problem[i] = (char*) malloc(32 * sizeof(char));
if((file_ID = fopen("INPUT_FILE.txt", "r")) == NULL )
printf(" The input file could not be open\n");
fscanf(file_ID, "%s %s %s %s\n", header, problem, problem, problem);
//Where the problem and problem may not exist in the file