Project-Scylla/KNR Redux/ex1-9.c

26 lines
483 B
C
Raw Permalink Normal View History

#include <stdio.h>
#include <stdlib.h>
int main(){
int c = 0;
_Bool lastWS = 0;
while((c = getchar()) != EOF){
//Check if the current character is a whitespace
if(c == '\t'|| c == ' '){
if(lastWS == 0){
//If the last character was not also WS, set lastWS 1 and print
lastWS = 1;
putchar(c);
}//If c is WS and last was WS, statement fails.
}
else{
//If not WS, set lastWS 0 and print.
lastWS = 0;
putchar(c);
}
}
putchar('\n');
exit(0);
}