/* echonospaces.c * Neal Nelson 2009.10.02 * * Echo lines with all spaces removed. * Overwrite the buffer provided by the caller. * */ #include #define MAXLINE 80 main() { char buf[MAXLINE]; while (fgets(buf, MAXLINE, stdin) != NULL ) { filter(buf,' '); printf ("%s\n", buf); } } /* filter out the character c from the buffer and squish */ filter(char *buf, char c) { char* p; for (p = buf; *p != '\0'; p++) { if ( *p != c ) { *buf++ = *p; } } *buf = '\0'; }