This is how I might do it, on a string literal. If it was a char array, I'd probably do the same, but use an index perhaps, instead of a pointer.
I don't like the mess of getc, getchar, fgetc, fgetchar, etc.. They're too close to being the same, but not. Sort of not hot, not cold, just lukewarm blah and you want to spit them out.
IMO, pointers and indeces are natural iterators for char strings and char arrays.
Code:
#include <stdio.h>
/* copy input to output; 1st version */
int main()
{
int skip;
char *c;
char *string = { "\nWater, water, everywhere,\nand all the boards did shrink\n water, water, everywhere and nary a drop to drink"};
printf("\n\n %s \n", string);
c = string;
skip = 0;
while (*c != '\0') {
if(*c == ' ' && skip == 1)
; //we be skipping! :)
else {
putchar(*c);
if(*c != ' ')
skip = 0;
}
++c;
if(*c == ' ' && skip == 0) {
skip = 1;
putchar(*c);
++c;
}
}
return 0;
}