如何让scanf()接收到b的值?
How can I make scanf () to receive the value of b?
int a,b;
while (scanf("%d",&a) != EOF){
printf("%d ",a);
}
printf("\n");
printf("Pls enter value b\n");
scanf("%d",&b);
printf("%d",b);
return 0;
当我输入然后用command + D跳出while循环时,此时无法再次输入,导致b的值随机。
正如其他人所建议的,您应该找到另一种方法来终止循环。虽然 ,这里有一个解决方法:
#include <stdio.h>
int main(){
int a,b;
while (scanf("%d",&a)!=EOF){
printf("%d ",a);
}
printf("\n");
printf("Pls enter value b\n");
freopen("/dev/tty", "r", stdin); /* Change /dev/tty to con: if you are using windows */
scanf("%d",&b);
printf("%d",b);
return 0;
}
您可以使用 freopen 强制从控制台输入。
我收到一封IntelliJ的邮件,你可以看到。
我键入 links 以便您可以访问 link。
电子邮件内容:
在 CLion 中发送 EOF 存在问题:https://youtrack.jetbrains.com/issue/CPP-5704. Disabling run.processes.with.pty is a workaround which helps to get the output printed after EOF. But this workaround has downsides like the one you faced with using scanf() after EOF. Unfortunately, there is no way to get both the output after EOF and scanf() after EOF working correctly until the issue (https://youtrack.jetbrains.com/issue/CPP-5704) is resolved. Feel free to comment or upvote the issue in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications 如果您不熟悉 YouTrack。
对于给您带来的不便,我们深表歉意。
此致,
安娜法列夫斯卡娅
捷脑
http://www.jetbrains.com
发展的动力
int a,b;
while (scanf("%d",&a) != EOF){
printf("%d ",a);
}
printf("\n");
printf("Pls enter value b\n");
scanf("%d",&b);
printf("%d",b);
return 0;
当我输入然后用command + D跳出while循环时,此时无法再次输入,导致b的值随机。
正如其他人所建议的,您应该找到另一种方法来终止循环。虽然 ,这里有一个解决方法:
#include <stdio.h>
int main(){
int a,b;
while (scanf("%d",&a)!=EOF){
printf("%d ",a);
}
printf("\n");
printf("Pls enter value b\n");
freopen("/dev/tty", "r", stdin); /* Change /dev/tty to con: if you are using windows */
scanf("%d",&b);
printf("%d",b);
return 0;
}
您可以使用 freopen 强制从控制台输入。
我收到一封IntelliJ的邮件,你可以看到。 我键入 links 以便您可以访问 link。 电子邮件内容: 在 CLion 中发送 EOF 存在问题:https://youtrack.jetbrains.com/issue/CPP-5704. Disabling run.processes.with.pty is a workaround which helps to get the output printed after EOF. But this workaround has downsides like the one you faced with using scanf() after EOF. Unfortunately, there is no way to get both the output after EOF and scanf() after EOF working correctly until the issue (https://youtrack.jetbrains.com/issue/CPP-5704) is resolved. Feel free to comment or upvote the issue in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications 如果您不熟悉 YouTrack。
对于给您带来的不便,我们深表歉意。
此致, 安娜法列夫斯卡娅 捷脑 http://www.jetbrains.com 发展的动力