samir82show

c_ch01_ex09.c

Sep 22nd, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. /*Exercise 1-9. Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank*/
  2.  
  3. #include <stdio.h>
  4. int main()
  5. {
  6. int flag = 0, c;
  7. while ((c = getchar()) != EOF) {
  8. if (c == ' ') {
  9. if (flag == 0) {
  10. putchar(c);
  11. flag = 1;
  12. }
  13. } else {
  14. putchar(c);
  15. flag = 0;
  16. }
  17. }
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment