I'm trying to read a txt file, get some information and put it in variables, but I'm not succeeding, because each line of my txt file starts with a character, and I need to skip that character.
Input file:
T1, 3, 0
T2, 3, 1
T3, 2, 2
I need to ignore the T and just take the numbers. I've tried using %*c
in fscanf
, but it didn't work.
int initialize()
{
int n, n1, n2, n3, i = 0;
FILE *fp;
fp = fopen("input.txt", "r");
if (fp == NULL)
{
printf("Error locating the file. Please try again!\n");
exit(1);
}
while (fscanf(fp, "%d, %d, %d", &n1, &n2, &n3) != EOF)
{
p[i] = n1;
if (p[i] > MAX)
{
printf("Woah! I am not a super computer. Please input upto 100 processes :)\n");
exit(1);
}
b[i] = n2;
a[i] = n3;
i++;
}
fclose(fp);
return i;
}
I apologize about my English, I'm from Brazil.