簡體   English   中英

如何在給出額外輸入的情況下使控制台輸出窗口在Visual Studio 2015中保持打開狀態?

[英]How to make the console output window stay open in Visual Studio 2015 stay open when extra input is given?

我在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;
}

該程序在所有情況下均可正常運行。 但是,當我提供“ Shabbir”,“ Shabbir K”和“ Shabbir Kh”作為輸入時,控制台窗口保持打開狀態。 如果我提供“ Shabbir Kha”作為輸入,則控制台窗口不會保持打開狀態。

如您所見,控制台窗口保持打開狀態,直到第二個單詞達到三個字符的長度。 如果第二個單詞的長度為三個或更多字符,則它不會保持打開狀態。

同一程序在代碼塊13.12中沒有顯示任何問題。

使窗口保持打開狀態:

while( getchar() != EOF );
getchar();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM