[英]scanf is reading new line character
对于%c
,手册页说(请参阅http://man7.org/linux/man-pages/man3/scanf.3.html ):
c Matches a sequence of characters whose length is specified by the maximum field width (default 1); the next pointer must be a pointer to char, and there must be enough room for all the characters (no terminating null byte is added). The usual skip of leading white space is suppressed. To skip white space first, use an explicit space in the format.
注意以下部分: 禁止通常的前导空白跳线。
还要注意以下部分: 要先跳过空格,请使用格式中的显式空格。
因此,如果要跳过空格,请尝试在%c
之前添加一个空格:
char c;
scanf(" %c", &c);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.