Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!nuchat!steve From: steve@nuchat.UUCP (Steve Nuchia) Newsgroups: comp.lang.c Subject: Re: FILE * <-> System File Handles Message-ID: <366@nuchat.UUCP> Date: Sun, 4-Oct-87 21:04:48 EDT Article-I.D.: nuchat.366 Posted: Sun Oct 4 21:04:48 1987 Date-Received: Wed, 7-Oct-87 07:01:24 EDT References: <2.bagpiper@oxy.uucp> Organization: Public Access - Houston, Tx Lines: 48 Summary: I don't know how to phrase this gently In article <2.bagpiper@oxy.uucp>, writes: > ahhhh...I had a problem the other day the I think may have something to do > with this. The following piece of code will clarify: > > #include > main() > { > FILE *otherptr ; > > fprintf(stdprn,"This goes to the system printer!!") ; > otherptr = strprn ; > fprintf(otherptr,"And so does this...(on the same line even)\n") ; > fclose(otherptr) ; > fprintf(stdprn,"But this doesn't....???????\n") ; > } It suprises you that stdprn is closed after you close it? What exactly do you expect that program to do? Lets look at it. You have a local variable of type FILE *. You assign the value stdprn to it. Then you pass that value (ie, stdprn) to fclose. Now, what would you expect to happen if you had said: fclose ( stdout ); fprintf ( stdout, "help, I can't talk anymore!\n" ); I would expect it to not be able to talk and thus it would say nothing. Now, recalling that this is C and not some hypothetical language we are discussing, how is fclose supposed to know the difference between fclose ( stdprn ); and foo = stdprn; fclose ( foo ); ????????? ***** SPOILER WARNING ***** It isn't. -- Steve Nuchia | [...] but the machine would probably be allowed no mercy. uunet!nuchat!steve | In other words then, if a machine is expected to be (713) 334 6720 | infallible, it cannot be intelligent. - Alan Turing, 1947