[英]How to make the console output window stay open in Visual Studio 2015 stay open when extra input is given?
I wrote the following program in Visual Studio 2015- 我在Visual Studio 2015中编写了以下程序
#include <stdio.h>
#define PRAISE "You are an extraordinary being."
int main(void)
#pragma warning(disable : 4996)
{
char name[40];
printf("What's your name? ");
scanf("%s", name);
fflush(stdin);
printf("Hello, %s. %s\n", name, PRAISE);
getchar();
getchar();
getchar();
getchar();
return 0;
}
The program runs fine in all cases. 该程序在所有情况下均可正常运行。 But the console window stays open when I provide "Shabbir", "Shabbir K", and "Shabbir Kh" as inputs. 但是,当我提供“ Shabbir”,“ Shabbir K”和“ Shabbir Kh”作为输入时,控制台窗口保持打开状态。 The console window won't stay open if I provide "Shabbir Kha" as input. 如果我提供“ Shabbir Kha”作为输入,则控制台窗口不会保持打开状态。
As you can see, the console window stays open until the second word reaches three character length. 如您所见,控制台窗口保持打开状态,直到第二个单词达到三个字符的长度。 It doesn't stay open if the second word is three or more characters long. 如果第二个单词的长度为三个或更多字符,则它不会保持打开状态。
The same program doesn't show any problems in Code Blocks 13.12. 同一程序在代码块13.12中没有显示任何问题。
to keep the window open: 使窗口保持打开状态:
while( getchar() != EOF );
getchar();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.