Advertisement
regzarr

problem 1

Oct 16th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. /* Collapse  spaces:
  5.  * Write  a  program  that  reads  all  input  and  prints  it  transformed as
  6.  * follows:
  7.  • any  sequence  of  whitespace  that  does  not  contain  newline  is
  8.    replaced  with  a single  space  character
  9.  • whitespace  characters  immediately  before  a  newline  are  deleted.
  10.  */
  11.  
  12. void collapseSpaces(){
  13.   char a = ' ', b;
  14.   while((b = getchar()) != EOF){
  15.     if((isspace(b) == 0) || (b == ' ' && isspace(a) == 0) || (b == '\n')){
  16.       printf("%c",b);
  17.     }
  18.     a = b;
  19.   }
  20. }
  21.  
  22. int main(){
  23.   collapseSpaces();
  24.   return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement