![](/img/trans.png)
[英]C - getchar() doesn't read the second character of an input correctly
[英]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.