In Kernighan and Ritchie (the C programming language):
Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.
I wrote the following code. Do you have advice to improve it?
#include <stdio.h>
/* copy input to output, replacing each
string of one or more blanks by a single blank */
main(){
int c;
double nc;
char otherBlank;
otherBlank = 'f';
while ((c = getchar()) != EOF){
if (otherBlank == 't' && c != ' '){
/* read a non blank and had a blank before */
putchar(' ');
putchar(c);
otherBlank = 'f';
}
else if (c == ' ')
/* read a blank */
otherBlank = 't';
else
/* read a non blank and had no blank before */
putchar(c);
}
}
otherBlank
eitherstdbool
'sbool
or atleastint
with 1/0 perhaps#define
d toTRUE
/FALSE
(old school) \$\endgroup\$