Verify that the expression getchar() != EOF is 0 or 1.

Source:

/* verify that expression getchar() != EOF is 0 or 1 */

#include "stdio.h"

int main(int argc, char *argv[])
{
  short int running = 1;
  /* make sure that getchar() always uses int
   * for proper EOF comparison! */
  int character;

  /* clear instructions for the user. */
  printf("Type anything and press [enter] to submit\nTo test EOF press [ctrl]+[d].\n");

  while(running == 1)
  {
      character = getchar();

    /* test if End Of File has been reached. */
    if(character != EOF && character != '\n')
    {
      printf("[%c]\n",character);
    }
    else if (character == '\n')
    {
      printf("[enter]\n");
    }
    else
    {
      printf("[EOF]\n");
      printf("Expression character!=EOF is: %i\n", (character!=EOF));
      return 0;
    }

  }

  return 0;
}

Output:

Type anything and press [enter] to submit
To test EOF press [ctrl]+[d].
[EOF]
Expression character!=EOF is: 0