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
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.
@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.
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.
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);
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With