/**Solution to exercise 5.6, p. 198, "C by Dissection" * * Counts the number of characters as they are written. When the count is N or more * write any white space as newline and change the count to zero. * * * 07. March, Lone Leth Thomsen **/ #include #include #define N 30 /* defines the width */ int found_next_char(void); int main(void) { int c; int char_count = 0; while ((c = getchar()) != EOF) { /* checks that the character is not EOF */ ++char_count; /* increases counter */ if (char_count < N){ /* checks width is less than N */ if (c != '\n') /* checks the character is not newline */ putchar(c); /* writes character */ else putchar(' '); /* writes space if the character was newline */ } else { if (!isspace(c)) /* if width reached check that the character is not a space */ putchar(c); else { putchar('\n'); /* if space found, add newline and reset count to zero */ char_count = 0; } } } return 0; }