Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

%*c in scanf() - what does it mean?

Tags:

c

scanf

I tried to run this program in Turbo C but couldn't decipher the output. What does this %*c mean? Any help would be appreciated.

int dd,mm,yy;
printf("\n\tEnter day,month and year");
scanf("%d %*c %d %*c %d",&dd,&mm,&yy);  // what does %*c mean ?
printf("\n\tThe date is : %d %d %d",dd,mm,yy);

OUTPUT

Enter day, month and year 23
2
1991
3
5
The date is: 23 1991 5
like image 476
Peps0791 Avatar asked Jul 18 '12 13:07

Peps0791


People also ask

What does %* c mean in c?

When passed as part of a `scanf` format string, “%*c” means “read and ignore a character”. There has to be a character there for the conversion to succeed, but other than that, the character is ignored. A typical use-case would be reading up to some delimiter, then ignoring the delimiter.

What does %* s mean in c?

@powersource97, %. *s means you are reading the precision value from an argument, and precision is the maximum number of characters to be printed, and %*s you are reading the width value from an argument, which is the minimum number os characters to be printed. – Vargas. Sep 24, 2021 at 20:50.

What does c mean in scanf?

Techopedia Explains Scanf Below are a few examples of the type specifiers recognized by scanf: %c — Character. %d — Signed integer. %x — Unsigned integer in hexadecimal format. %f — Floating point.

What does %* D mean in c?

The %*d in a printf allows you to use a variable to control the field width, along the lines of: int wid = 4; printf ("%*d\n", wid, 42);


1 Answers

The * after % in a format string signify that the input matching the format will be ignored (thus no need to pass in a pointer to a variable to store the matched value that you are not going to use).

like image 114
nhahtdh Avatar answered Oct 04 '22 00:10

nhahtdh