Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!sri-spam!mordor!lll-tis!ames!sdcsvax!ucsdhub!jack!man!nusdhub!rwhite From: rwhite@nusdhub.UUCP (Robert C. White Jr.) Newsgroups: comp.lang.c Subject: Re: FILE * <-> System File Handles Message-ID: <114@nusdhub.UUCP> Date: Sat, 3-Oct-87 21:50:22 EDT Article-I.D.: nusdhub.114 Posted: Sat Oct 3 21:50:22 1987 Date-Received: Thu, 8-Oct-87 01:29:17 EDT References: <2.bagpiper@oxy.uucp> Organization: National University, San Diego Lines: 27 Summary: Simple Anwser to file problem. In article <2.bagpiper@oxy.uucp>, writes: > 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") ; > Your problem is very simple. The type of stdprn is a pointer to FILE. You coppied the pointer value from stdprn into otherptr. When you closed otherprinter you were pointing to te same thing as stdprn. Since both of the pointers are identical [and therefore have the same MS-DOS file handle] the single handle was closed. Remember type FILE is a structure one entry of which is the file handle is only one part. This also holds true for any UNIX STREAM. Instead of the asignment you did in the code fragment, you should have either used dup() or dup2() functions so that you had 2 seprate files open to the same device. NOTE: on MS-DOS versions before 3.0 the close will still cause futrue writes to fail [do to an ms-dos bug] because the close routine will still sometimes close both file handles (this from my Microsoft C manual.) The code works correctly for 3.0 ms-dos and above. Robert ("So who asked you anyway?") White.