Exercise 1.9:

alendr · updated September 15, 2021 · C
#include <stdio.h>
#define NONBLANK 'a' 
/* replace string of blanks with single blank */ 


int main() {
    int c, lastc; 
    lastc = NONBLANK; 
    while ((c = getchar()) != EOF) {
        if (c != ' ')
            putchar(c); 
        if (c == ' ')
            if (lastc != ' ') 
                putchar(c); 
        lastc = c;                 }          
        /*         printf("Printing at the end:", c, lastc);} */ 
           }

Comments

Please sign up or log in to contribute to the discussion.