Copy its input to its output, replacing each string of one or more blanks by a single blank. - C Data Type

C examples for Data Type:char

Description

Copy its input to its output, replacing each string of one or more blanks by a single blank.

Demo Code

#include <stdio.h>

int main(void){
    int c, blank_recieved = 0;
    //from   w  w w . ja  va 2 s . c o  m
    printf("Input some characters, when you finishes, press Ctrl+D.\n");
    
    while ((c = getchar()) != EOF){
        if (c == ' ') {
            if (!blank_recieved) {
                blank_recieved = 1;
                putchar(c);
            }
        } else {
            blank_recieved = 0;
            putchar(c);
        }
}
    return 0;
}

Result


Related Tutorials