acobzew

sem2-problem1

Mar 13th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. #define STR_LEN 100
  5.  
  6. int main() {
  7.     char s[STR_LEN], c;
  8.     int i = 0, j;
  9.     bool inword = false;
  10.     while ((c = getchar()) != EOF) {
  11.         if (c == ' ' || c == '\t') {
  12.             if (inword) {
  13.                 inword = false;
  14.                 s[i++] = '\n';
  15.             }
  16.         }
  17.         else {
  18.             inword = true;
  19.             s[i++] = c;
  20.         }
  21.     }
  22.  
  23.     for (j = 0; j < i; j++)
  24.         putchar(s[j]);
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment