|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
i have a question about one of the exercises in the k & r book....
hey,
i have a question for someone who has the book, "THE C PROGRAMMING LANGUAGE [2nd Edition]"....... on page 17 and exercise 1-6 it says, "Verify that the expression getchar() != EOF is 0 or 1." what does this mean? how would i do this? thanks a lot, -sean
__________________
"I speak English, can you type it?" -Everett_XML |
|
#2
|
||||
|
||||
|
Basically in C, a comparision evaluates to 0 (false) or 1 (true). An if statement like this:
if (getchar() != EOF) { ... } will cause the compiler to evaluate the comparision expression as a 1 (true) or a 0 (false). You could actually assign the result of the comparision to another variable, if you like, something like this: Code:
int foo;
if (foo = (getchar() != EOF)) {
/* Do something */
}
printf("%d\n", foo);
the value of foo will be 0 or 1 depending on whether the getchar() returned an end-of-file character or not. Hope this helps! |
|
#3
|
||||
|
||||
|
Curious - when would getchar() EVER return EOF? Or, is that what it returns when you hit enter?
|
|
#4
|
||||
|
||||
|
Nope, the enter key is not the EOF char on any OS that I'm aware of. On *NIX, the EOF character is ^D and on DOS, EOF is ^Z.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > i have a question about one of the exercises in the k & r book.... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|