int c;
while ((c = getchar()) != EOF)
putchar(c);
"This value is called EOF, for "end of file". We must declare c to be a type big enough to hold EOF in addition to any possible char. Therefore we use int."
Correct me if i am wrong:
- (signed) char = [-128. +127]
- unsigned char = [0, 255]
- EOF = -1
when I replace int
with char
in the above program it seems to work like intended , but after some research I found out that it doesn't because the variable c
cannot store -1 aka EOF
( albeit using char
).
I run it anyway and tried to crash it, I tried to input negative number like -1 but it didn't work. I believe that is because it is interpreted like 2 different characters -
and 1
. I tried ÿ
which is the character corresponding to ascii value 255 according to http://ascii-code.com/,
so for what input will the above program ( using char
instead of int
) crash ?
(For information, I am using a 64bit fedora Linux)