Advertisement
Lisaveta777

Prata list 8.5

Aug 19th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. //i have to rid of everything, and leave only basic, to find out, how exactly combination of getchar() and
  3. //scanf() works, when they share potok
  4. //now i can't predict, what happened if i enter
  5. //s k 1 2 and why
  6. //.....
  7. //i have to be able to predict exactly the way programm works, before running it
  8.  
  9.  
  10. void display(char cr, int lines, int width);
  11.  
  12. int main(void)
  13. {
  14.     int ch; /* character to be printed */
  15.     int rows, cols; /* number of rows and columns */
  16.     printf("Enter a character and two integers:\n");
  17.  
  18.     while ((ch = getchar()) != EOF)//if '\n' instead of EOF, works just once!
  19.     {
  20.         printf("before scanf rows is %d, cols is %d\n",rows,cols);
  21.         printf("scanf returns %d elements\n", scanf("%d %d", &rows, &cols));
  22.         printf("after scanf rows is %d, cols is %d\n",rows, cols);
  23.         //scanf("%d %d", &rows, &cols);
  24.         display(ch, rows, cols);
  25.         printf("Enter another character and two integers;\n");
  26.         printf("Enter a newline to quit.\n");
  27.     }
  28.     printf("Bye.\n");
  29.  
  30. return 0;
  31. }
  32.  
  33. void display(char cr, int lines, int width)
  34. {
  35.     int row, col;
  36.     for (row = 1; row <= lines; row++)
  37.     {
  38.         for (col = 1; col <= width; col++)
  39.         putchar(cr);
  40.         putchar('\n'); /* end line and start a new one */
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement