Xref: utzoo comp.sys.ibm.pc:27881 comp.binaries.ibm.pc.d:2799 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!noao!arizona!naucse!wew From: wew@naucse.UUCP (Bill Wilson) Newsgroups: comp.sys.ibm.pc,comp.binaries.ibm.pc.d Subject: Re: HELP need in C (turbo c, fopen problem) Message-ID: <1372@naucse.UUCP> Date: 25 Apr 89 18:00:51 GMT References: <353@h.cs.wvu.wvnet.edu> Organization: Northern Arizona University, Flagstaff, AZ Lines: 35 From article <353@h.cs.wvu.wvnet.edu>, by packer@a.cs.wvu.wvnet.edu (Michael A Packer): > > i am trying to open a file. When i open the file my filepointer is > being returned (not null). When i look at what fp is pointing to > there is garbage in the "buffer" and "curp" as declared by FILE. > > if ((fp=fopen("junk.dat","w"))==NULL) > { > printf ("Can't open file\n"); > return; > } > fopen simply opens a file and associates a "stream" with it. The pointer may then be used by other functions that use a stream to operate. For example to read from the stream, you could use the following: while (!feof(in)) putc(fgetc(fp)); The file pointer is only used by the functions that work with streams and are not in essence an actual pointer into the file as I understand it. You will need to use the fread or fget function to read from the file and there are equivalent functions to write. The manual (if you have one) shows how to work with the function. It even gives an example in the 2.0 manual for making a copy of a file on page 135 (Reference Guide). Good Luck. -- Bill Wilson (Bitnet: ucc2wew@nauvm) Northern AZ Univ Flagstaff, AZ 86011 {He's Watching me Watching you Watching him...}