Whitespace before %c specification in the format specifier of scanf function in C [duplicate]

只愿长相守 提交于 2019-11-28 02:16:29

If you read the specification for scanf() carefully, most format specifiers skip leading white space. In Standard C, there are three that do not:

  • %n — how many characters have been processed up to this point
  • %[…] — scan sets
  • %c — read a character.

(POSIX adds a fourth, %C, which is equivalent to %lc.)

Input white-space characters (as specified by isspace) shall be skipped, unless the conversion specification includes a [, c, C, or n conversion specifier.

Adding the space between %d and %c means that optional white space is skipped after the integer is read and before the (not white space) character is read.

A space before %c specifier in scanf instruct it to skip any number of white-spaces. In other words, read from standard input until and unless a non-white-space character or keyboard interrupt is found.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!