TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: F. Tourigny
from: Darin McBride
date: 1998-07-14 20:22:42
subject: EOF(2)

FT>  I've been trying my hand at Exercise 1-6 in K&R
 FT>  with VC4:

 FT>  int main(void)   /* verify that getchar() != EOF is 0 or 1 */
 FT>  {
 FT>         int c;
 FT>  
 FT>         printf("Enter char: ");
 FT>         printf("getchar() != EOF is: %d", c = getchar() != EOF);
 FT>         return 0;
 FT>  }

Hmmm... let's look at that line again, but let's put the invisible
parenthesis in there so we know what's going on:

 FT>         printf("getchar() != EOF is: %d", c = (getchar() != EOF));

c is assigned either 0 or 1 - is this what you want?

 FT>  If I enter a character, I get 1, which is OK if
 FT>  the above code is good.  Nonzero is True, right?

Yup.

 FT>  If I try the following line instead:
 FT>         printf("getchar() == EOF is: %d", c = getchar() == EOF);
 FT>  and type a character, I get 0.

 FT>  Is this line of reasoning correct?

Yup.

 FT>  The next exercise outputs -1:

 FT>  /* write a program to print the value of EOF */

 FT>         printf("%d\n", EOF);

As expected.  However, you can't type -1.  :-)

Depending on your platform, either Ctrl-Z or Ctrl-D is your EOF
character... the former for DOS, Win32, OS/2, and the latter for
unix-variants.  (Warning: you can change the EOF character on
unix-variants, so it may be different...)


---
* Origin: Tanktalus' Tower BBS (1:250/102)
SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728
SEEN-BY: 639/252 670/213 218
@PATH: 250/102 201 99 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.