私はCの初心者ですので、この質問がばかげているか、奇妙な質問をしている場合はご容赦ください。
私はCprimerplusを読んでおり、第8章の例の1つは、ユーザーが入力したかどうかをテストするループですa newline character or not
。これは理解できませんでした。
コードが短いので、以下に示します。
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
私が理解していないことはここにあります:
while (getchar() != '\n')
continue;
printf("Enter another character and two integers;\n");
printf("Enter a newline to quit.\n");
まず第一にwhile (getchar() != '\n')
、最初のchが正しく入力されたテストですか?第二に、それが本当なら、なぜcontinueはprintfステートメントをスキップせずに最初のwhileに行くのですか?それはそれが何をすべきかではありませんか?
Tnx