2011-03-24 65 views
0

部分如下,但是不行驗證碼的輸入

printf("Enter a line of text (Enter to stop): "); 
    fflush(stdin); 
    fgets(input, 256, stdin); 

    if (input == '\0') { 
    exit(0); 
    } 

    ..... 
    ..... 

我想,如果用戶只按回車鍵,該程序將被終止。怎麼做? 謝謝

+0

fflush(stdin)?這完全是未定義的行爲,因爲fflush()僅適用於輸出流。我認爲你的意思是fflush(標準輸出)。 – Shinnok 2011-03-24 08:39:30

回答

0

使用if(*input == '\n') - 如果fgets讀取換行符,它將存儲在緩衝區中。