Write a program that counts white space (spaces, tabs, newlines).

Source:

#include "stdio.h"

int main(int argc, char *argv[])
{
  int running = 1;

  int character;

  int whitespace_counter = 0;

  printf("Enter a bunch of text and I will count whitespace!.\n[ctrl]+[d] to quit.\n");

  while(running)
  {
    character = getchar();

    if(character != '\n' && character != EOF && character != ' ' && character != '\t')
    {
      printf("%c", character);
    }
    else if(character == ' ')
    {
      printf(" ");
      whitespace_counter += 1;
    }
    else if(character == '\t')
    {
      printf("    ");
      whitespace_counter += 1;
    }
    else if(character == '\n')
    {
      /*whitespace_counter += 1;*/
      printf("[enter] whitespace=%i\n", whitespace_counter);
      whitespace_counter = 0;
    }
    else if(character == EOF)
    {
      printf("[EOF] = %i\n", character);
      running = 0;
    }
  }

  return 0;
}

Output:

Enter a bunch of text and I will count whitespace!.
[ctrl]+[d] to quit.
This is just a test.
This is just a test.[enter] whitespace=4
[EOF] = -1