Write a program that prints its output one word per line.

Source:

/* print the input one word per line. */
/* word defined by letters surrounded by whitespace. */
#include "stdio.h"

#define TRUE 1
#define FALSE 0

typedef signed char bool; 

int main(int argc, char *argv[])
{
  int character = ' ';
  bool in_word = FALSE;
  bool running = TRUE;

  printf("Type a few words. I will print them one per line.\n[Enter] to submit. EOF (ctrl+d) to quit.\n");
  printf("----------------------------------------------------------------------------------\n");

  while(running)
  {
    character = getchar();

    if(character == '\n' || character == ' ' || character == '\t' || character == EOF)
    {
      if(in_word)
      {
        in_word = FALSE;
        printf("\n");
      }
      /* otherwise do nothing, we don't to print excessive new lines/tabs/spaces. */
    }
    else
    {
      in_word = TRUE;
      printf("%c", character);
    }
    /* so we will test for EOF to quit here.*/
    if(character == EOF)
    {
      printf("\n");
      running = FALSE;
    }
  }

  printf("----------------------------------------------------------------------------------\n");
  return 0;
}

Output:

Type a few words. I will print them one per line.
[Enter] to submit. EOF (ctrl+d) to quit.
----------------------------------------------------------------------------------
One word per line.
One
word
per
line.

----------------------------------------------------------------------------------