I am working through K&R and have gotten to exercise 1-6 which asks you to
Code:
Verify that the expression getchar() != EOFis 0 or 1.
I am confused about what exactly this is asking. I may be over thinking this or just not understanding what they mean. Do they mean do this?
Code:
#include <stdio.h>
int main()
{
int c;
if ((c = getchar()) != EOF) {
putchar(c);
return 0;
}
else if ((c = getchar()) == EOF) {
putchar(c);
return 1;
}
}
If someone could elaborate on what they are asking for that would be amazing! I would look it up, but I am afraid I'll find the answer which isn't what I want.
#Solution:
I got confused by directions, but luckily my code was correct. However, as a bonus if you look at this code it can be trimmed. I.E.
Code:
#include <stdio.h>
int main()
{
int c;
if ((c = getchar()) != EOF) {
putchar(c);
return 0;
}
}