Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Exercise 1-12.
- * Write a program that prints its input one word per line.
- */
- #include <stdio.h>
- #define IN 1 /* inside a word */
- #define OUT 0 /* outside a word */
- /* count lines, words, and characters in input */
- main() {
- int c, state;
- state = OUT;
- while ((c = getchar()) != EOF) {
- if (c == ' ' || c == '\n' || c == '\t') {
- if (state == IN) {
- state = OUT;
- putchar('\n');
- }
- } else {
- state = IN;
- putchar(c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment