【发布时间】:2014-07-15 04:34:28
【问题描述】:
我做了以下操作,但它跳过了我必须输入字符的部分,我不明白我的错误是什么。有什么帮助吗?
#include <stdio.h>
main()
{
int num;
float f;
char c;
printf("Input an integer: ");
scanf_s("%d", &num);
printf("Input an floating point number: ");
scanf_s("%f", &f);
printf("Input a character: ");
scanf_s("%c", &c);
printf("\nThe number is: %d\n",num);
printf("\nThe floating point number is: %f\n", f);
printf("\nThe character is: %c\n", c);
return 0;
}
【问题讨论】:
-
那么您是在询问打印您在标题中所说的字符,还是询问读取您在文本中所说的字符?
-
问题/标题可能有点模糊,但问题不是。这是
scanf()和换行符的标准问题。我确定有数百个重复项,但我找不到任何 ATM... -
scanf_s("%c", &c);-->scanf_s(" %c", &c, 1); -
非常感谢,它确实有效。
标签: c