Mail Archives: djgpp/1999/01/28/15:20:39
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
- Raw text -