Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: Assigning an array to a FILE structure Keywords: file I/O, streams Message-ID: <474@taumet.com> Date: 11 Oct 90 15:39:07 GMT References: <1389@ashton.UUCP> Organization: Taumetric Corporation, San Diego Lines: 20 tomr@ashtate (Tom Rombouts) writes: >They say the only stupid question is the one that isn't asked, so: >Is it possible using the ANSI stream I/O functions to assign an >array to a FILE structure so that fgetc() etc. will work on it? There is no portable way to do this in ANSI C. You could assign your own buffer to the FILE structure, and figure out how to set the related pointer and size fields of the structure to correspond. But the stdio library is still going to assume an open file somewhere, and try to use low-level read calls to get more data -- this won't work, of course. You can do this easily in C++, since the stream (and iostream) library explicitly supports using a character array as if it were a file -- all the I/O and EOF operations work correctly with no attention from the programmer. -- Steve Clamage, TauMetric Corp, steve@taumet.com