0

While reading from a file in C, I was told that I can add an * after the % to disregard that input. For example:

fscanf(inputfile, "%lf %lf %*lf", &num1, &num2);

In this example the pointer reads three double values, but only two of them need to be stored (the ones without the * sign after the % sign).

Could someone explain how it works, because as far as I know the * sign is used to initialize or step into a pointer?

Ahijit
  • 113
  • 2
  • 15

1 Answers1

2

The use of * is just a string constant chosen arbitrarily. It has no relation to pointer dereferencing. How it "works" is that the parser in scanf simply parses the type as it would normally then throws away the value rather than looking for a parameter to put it in.

LoztInSpace
  • 5,584
  • 1
  • 15
  • 27