So I’m reading K&R book and I have a question regarding this code:
int c;
c = getchar();
Why do they use integer variable? Isn’t the value that getchar() returns a character? So a char would be more suitable? Please enlighten me.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
getchar()needs to be able to indicate when it’s reached the end of the input. It does this by returningEOF, which is deliberately outside the validcharrange so it can’t clash with a character appearing on the input.