扫描功能没有取值...它只是显示打印功能
The scan function isn't taking values in... It is just displaying the print function
void kmmil()
{
int x, y;
printf("a.KM TO MILS\n");
printf("b.MILS TO KM\n");
char c;
scanf("%c", &c);
printf("this is the value %c", c);
}
输出:
this is the value (blank)
结束;
如果 scanf“不起作用”,它通常会起作用,但不是以我们预期的方式起作用。如果您的代码中有另一个 scanf,例如扫描一个数字。您在终端中输入类似 123 的内容,然后按回车键确认。然而,该输入保留在输入中并等待被某些东西扫描。这可能就是您的 scanf “不起作用”的原因。关于解决方案:
我建议你清除你的输入。您至少可以在
scanf("%*[^\n]"); // scan and delete everything until newline character
scanf("%*c"); // scan and delete one more character (newline)
或
while(getchar() != '\n'); // get characters until newline (note that newline is deleted this way too!)
void kmmil()
{
int x, y;
printf("a.KM TO MILS\n");
printf("b.MILS TO KM\n");
char c;
scanf("%c", &c);
printf("this is the value %c", c);
}
输出:
this is the value (blank)
结束;
如果 scanf“不起作用”,它通常会起作用,但不是以我们预期的方式起作用。如果您的代码中有另一个 scanf,例如扫描一个数字。您在终端中输入类似 123 的内容,然后按回车键确认。然而,该输入保留在输入中并等待被某些东西扫描。这可能就是您的 scanf “不起作用”的原因。关于解决方案:
我建议你清除你的输入。您至少可以在
scanf("%*[^\n]"); // scan and delete everything until newline character
scanf("%*c"); // scan and delete one more character (newline)
或
while(getchar() != '\n'); // get characters until newline (note that newline is deleted this way too!)