我是C的初學者,所以請原諒我這個問題是愚蠢的還是奇怪的問。在測試真實條件後,如何進行printf?
我讀Ç底漆加和在章-8一個例子是一些環路測試用戶是否進入 - 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')
正在測試的第一章是輸入正確嗎?第二,如果這是真的,繼續如何不滑動printf語句並且首先進行?不是它應該做什麼?
TNX
「我正在讀C primer plus」<---這是你最大的問題!用火殺死那本書! RTFN –
「繼續」只是煙。最好是'while(getchar()!='\ n');'。 –
謝謝分配:) @Daniel Fischer – MNY