您的位置:首页 > 其它

while (getchar() != '\n')

2016-04-16 16:41 267 查看
/*问题:while (getchar() != '\n')continue;   跳过一行的剩余字符时间:2016/4/16*/#include <stdio.h>void display(char ch, int height, int width);int main(void){int ch;int rows, cols;printf("enter a character and two integers:\n");while ((ch = getchar()) != '\n'){if (scanf_s("%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");}return 0;}void display(char ch, int height, int width){for (int row = 0; row < height; row++){for (int col = 0; col < width; col++)putchar(ch);putchar('\n');}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: