1
0

showchar2.c 922 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* showchar2.c -- prints characters in rows and columns */
  2. #include <stdio.h>
  3. void display(char cr, int lines, int width);
  4. int main(void)
  5. {
  6. int ch; /* character to be printed */
  7. int rows, cols; /* number of rows and columns */
  8. printf("Enter a character and two integers:\n");
  9. while ((ch = getchar()) != '\n')
  10. {
  11. if (scanf("%d %d",&rows, &cols) != 2)
  12. break;
  13. display(ch, rows, cols);
  14. while (getchar() != '\n')
  15. continue;
  16. printf("Enter another character and two integers;\n");
  17. printf("Enter a newline to quit.\n");
  18. }
  19. printf("Bye.\n");
  20. return 0;
  21. }
  22. void display(char cr, int lines, int width)
  23. {
  24. int row, col;
  25. for (row = 1; row <= lines; row++)
  26. {
  27. for (col = 1; col <= width; col++)
  28. putchar(cr);
  29. putchar('\n'); /* end line and start a new one */
  30. }
  31. }