/*
 * Problem 1-6
 * Verify that the expression getchar() != EOF is 0 or 1.
 * Copyright (c) 1998 by John Weber.  All rights reserved.
 */
#include <stdio.h>

/* We note that a character is a byte. Therefore, for unsigned 
   char there are 256 values 0-255 (for signed char the values 
   range from -128 to 127).  So getchar() can only possibly 
   return one character ranging from -128 to 255.  We can 
   verify that the expression getchar() != EOF is either 0 or 1 
   by trying all of these values. */

int main(void)
{
	int c;

	if( (EOF != EOF) != 0 ) {
		printf("something is really wrong!\n");
		exit(1);
	}

	for( c = -128; c <= 255; c++ ) {
		if( (((char)c != EOF) != 1) && (((char)c != EOF) != 0) ) {
			printf("getchar() != EOF may return value other than 1 or 0\n");
			return 0;
		}
	}

	printf("getchar() != EOF always returns 1 or 0\n");
	return 0;
}
