Hello all,
I am trying to parse a text file that has the following format:
3
1:3,60,3
2:6,70,1
3:3,50,3
I am supposed to take the first line "3", and allocate memory for the 3 lines after it.
Then I want to skip the first line, and start parsing and tokenizing the the next 3 lines into a struct array.
I wrote the code below, but it is not working. Please note that I am a beginner in C, and I wrote this according to my very basic knowledge about C:
if((file=fopen(textFile, "r"))!=NULL)
{
fscanf(file,"%d",&numberOfFlows);
}
printf("%d", numberOfFlows);
newFlows = malloc(sizeof(Flow)*numberOfFlows);
int i;
for(i = 0; i < (1+numberOfFlows); i++)
{
char *flow = malloc(sizeof(char)*15);
fgets(flow, 15, file);
char flowNo = flow[0];
strtok(flow,":");
char *arrivalTime = strtok(NULL, ",");
char *transmissionTime = strtok(NULL, ",");
int priority = flow[3];
free(flow);
}
fclose(file);
Please guide me to how modify this code.
Thanks in advance