khalfella

c_ch01_ex09.c

Sep 20th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. /*
  2. * Exercise 1-9.
  3. * Write a program to copy its input to its output, replacing
  4. * each string of one or more blanks by a single blank.
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. main() {
  10. int c, pc;
  11.  
  12. /*
  13. * set the previous character to anything
  14. * other than blank
  15. */
  16.  
  17. pc = 'A';
  18.  
  19. while ((c = getchar()) != EOF) {
  20. if (c == ' ' && pc == ' ')
  21. ;
  22. else {
  23. putchar(c);
  24. pc = c;
  25. }
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment