Subject: Re: Need help with c! Approved: clc AT plethora DOT net Content-Transfer-encoding: 7bit Sender: news AT arl DOT mil (News Administration ) X-Nntp-posting-host: swctd.arl.mil References: From: "Douglas A. Gwyn" Organization: US Army Research Laboratory (ISTD/CNSD) X-Accept-language: en Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: comp.os.msdos.djgpp,comp.lang.c.moderated Message-ID: X-Mailer: Mozilla 4.5 [en] (X11; I; SunOS 5.7 sun4u) Originator: clcm AT plethora DOT net (Comp Lang C'Moderated) Lines: 51 Date: Thu, 28 Jan 1999 20:17:00 GMT NNTP-Posting-Host: 205.166.146.5 X-Trace: ptah.visi.com 917554620 205.166.146.5 (Thu, 28 Jan 1999 14:17:00 CDT) NNTP-Posting-Date: Thu, 28 Jan 1999 14:17:00 CDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Marp wrote: > Get rid of the word static in front of FILE *fptr because that should be > able to change as you work with the file. If it can't change it won't work > properly. That's nonsense. "static" != "const" > Mohanaraj Gopala Krishnan wrote in message ... > > if((fptr=fopen("chapter.dat", "r")) !=NULL) ... > > else if((fptr=fopen("chapter.dat","w+b")) !=NULL) ... > > else { > > printf("Cannot open or start new chapter!!!"); > > exit(1); > > } > >The problem is with the first open and read only line. If there is no > >chapter.dat file in the program it is okay, but once the chapter.dat > >file already exists, the program quits straight away. I don't know what operating system you're using, but it is inconsistent to write a file as a binary stream then try to read it as a text stream. > >void > >main() > >{ That's wrong; main returns an int. > >void read_page(char * strpointer) > >{ > > FILE *page_write; > > PAGE page; > > > > page_write=fopen("chapter.dat","r"); > > if(page_write==NULL) > > { > > puts("No chapter found!!"); > > return; > > } > > > > fread(strpointer,sizeof(page),1,page_write); > >} The above function loses the FILE* handle without first closing the open stream. It is also a serious error to try to use a character string instead of an open FILE* for the first argument to fread(). There are probably other problems, but in general I didn't see a clear model that your I/O functions were implementing. -- comp.lang.c.moderated - clcm AT plethora DOT net