Use
while((r = fscanf(file, " %c\t%d", &id, &num)) != EOF) //Whitespace before %c
You can solve your problem. Because when you use
fscanf(file, "%c\t%d", &id, &num)
Then it leaves a newline character, which is consumed in the next iteration. As the next iteration, your id gets \n and num gets the character.
But when you put an extra space before %c , which tells fscanf() ignore spaces (including Tab, space or new line). This way your fscanf() gets two parameters (character and number).
source share