What is the format specifier used to read character input with 'scanf()' in C?

The format specifier used to read character input with scanf() in C is %c.

However, it's important to add a space before %c to consume any leftover newline character from previous inputs. Here’s an example:

char c;
printf("Enter a character: ");
scanf(" %c", &c); // Note the space before %c

This ensures that scanf() waits for new input instead of reading the leftover newline character.

0 Comments

no data
Be the first to share your comment!