Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

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

Related questions

1 answer 78 views
2 answers 91 views
91 views asked Nov 11, 2016 by avibootz
1 answer 58 views
...