0

I have a gotten a C program, where one of the line having:

scanf("%d%*c%d", &x, &y);

What is the meaning of %*c?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
opu 웃
  • 464
  • 1
  • 7
  • 22

2 Answers2

6

scanf reads data from stdin and then it stores that data into the parameters pointed according to the format (in your case the parameters are &x and &y).

*indicates that the data is to be read from the stream but ignored (i.e. it is not stored in the location pointed by an parameter).

In your case %*c means that the function reads a datatype char but does not store it into an instance. It is useful if you want to ignore a part of a string, like the character.

Edenia
  • 2,312
  • 1
  • 16
  • 33
1

From http://beej.us/guide/bgc/output/html/multipage/scanf.html

*

Tells scanf() do to the conversion specified, but not store it anywhere. It simply discards the data as it reads it. This is what you use if you want scanf() to eat some data but you don't want to store it anywhere; you don't give scanf() an argument for this conversion. Example: %*d.

Community
  • 1
  • 1
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501