私はCの初心者ですので、この質問が愚かであるか奇妙なことに尋ねている場合は、私を許してください。 a newline character or not
、私は理解できませんでした -真の条件がテストされた後、printfはどのように実行されますか?
は、私はCプライマープラスと章-8の例のいずれかを読んでいると、ユーザーが入力したかどうかをテストするいくつかのループです。 while (getchar() != '\n')
は、最初のchがいたテストして、すべての
while (getchar() != '\n')
continue;
printf("Enter another character and two integers;\n");
printf("Enter a newline to quit.\n");
まず:
コードが短いですので、私はあなたにそれを表示します:どのような私が理解しないことは右ここにある
int main(void)
{
int ch; /* character to be printed */
int rows, cols; /* number of rows and columns */
printf("Enter a character and two integers:\n");
while ((ch = getchar()) != '\n')
{
if (scanf("%d %d",&rows, &cols) != 2)
break;
display(ch, rows, cols);
while (getchar() != '\n')
continue;
printf("Enter another character and two integers;\n");
printf("Enter a newline to quit.\n");
}
printf("Bye.\n");
return 0;
}
void display(char cr, int lines, int width) // the function to preform the printing of the arguments being passed
右に入った? 第2に、それが真実なら、どのようにしてprintfステートメントをスキップして最初の状態に進まないのでしょうか?それは何をすべきか? TNX
"私はCプライマープラスを読んでいます" <---それはあなたの最大の問題です!火災でその本を殺す! RTFN –
'continue'はただの煙です。 'while(getchar()!= '\ n');'とするのが良いでしょう。 –
ありがとうございます:) @Daniel Fischer – MNY