/* EXERCISE 1-18 */ #include <stdio.h> #define MAXWHITE 40 /* A SMALL NUMBER FOR TESTING */ #define YES 1 #define NO 0 main() { int c, i, j, prtlin, error; char s[MAXWHITE]; /* TO HOLD CONSECUTIVE BLANKS AND TABS */ i = 0; prtlin = NO; error = NO; while ((c = getchar()) != EOF) if (c == '\n') { if (prtlin == YES) { prtlin = NO; putchar('\n'); } if (error == YES) { error = NO; printf("\nEMBEDDED BLANKS AND TABS TRUNCATED\n"); } i = 0; } else if (c == ' ' || c == '\t') { if (i < MAXWHITE) s[i] = c; ++i; } else { if (i > 0) { if ( i > MAXWHITE) { i = MAXWHITE; error = YES; } for (j = 0; j < i; ++j) putchar(s[j]); i = 0; } putchar(c); prtlin = YES; } /* PRINT A NEWLINE CHARACTER FOR THE LAST LINE, IF NECESSARY */ if (prtlin == YES) putchar('\n'); if (error == YES) printf("EMBEDDED BLANKS AND TABS TRUNCATED\n"); printf("\nEND OF PROGRAM\n"); return 0; }