簡體   English   中英

getchar函數不打印第二個輸入嗎?

[英]Don't getchar function print the second input?

#include <stdio.h>
int main()
{
    char gh, hj;
    printf("Enter the first letter of your name \n");
    gh=getchar();
    printf("Enter the last letter of your name\n");
    hj=getchar();
    getchar();
    printf("The first and last leter of your name is %c%c", gh, hj);
    return 0;

}

當我運行此代碼時,與第一個%c不同,第二個%c不會被打印。 為什么會這樣呢?

由於第二個getchar細讀您輸入的字符之后的換行符。

暫無
暫無

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

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