How to copy input to output and replace multi blanks by a single blank in C

1 Answer

0 votes
#include <stdio.h> 

int main(void)
{   
    char ch;
    
    printf("Enter a sentence (Enter + Ctrl-c to Exit): ");
    ch = getchar();
 
    while (ch != EOF)
    {
        if (ch==' ')
            putchar(ch);
        
        while (ch == ' ')
            ch = getchar();
        
        putchar(ch);
        ch = getchar();
     }
         
    return 0;
}


 
/*
run:
   
Enter a sentence (Enter + Ctrl-c to Exit): c is    on   of the      best
c is on of the best

*/

 



answered Nov 10, 2016 by avibootz
...