Why is printf executed after checking the true state?

I am new to C, so please forgive me if this question is stupid or strange asked.

I am reading C primer plus, and one example in chapter 8 is a loop that checks if a user is entered - a newline character or notwhich I could not understand.

The code is short, so I will show it to you:

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 

What I don't understand is here:

while (getchar() != '\n')
                continue;
            printf("Enter another character and two integers;\n");
            printf("Enter a newline to quit.\n");

First of all, while (getchar() != '\n')checks that the first ch was entered correctly? Secondly, if this is so, then why does the continuation not skip the printf statements and move on to the first? Isn't that what he should do?

Tpx

+5
source share
4 answers

while , . , continue while , , printf.

:

 while (getchar() != '\n')
 {
    continue;
 }
+7

while printf -s, , \n, ,

printf("Enter another character and two integers;\n");
+1

continue while.

while (stuff)
  continue;

while (stuf);

( ).

" , ".

0

while() continue. printf..........

0

All Articles