Article View: comp.sys.acorn.tech
Article #220Re: problem with fprintf & DTC
From: Edward Nevill
Date: Wed, 07 Oct 1992 10:52
Date: Wed, 07 Oct 1992 10:52
26 lines
1405 bytes
1405 bytes
> I'm having a problem with fprintf( using Desktop C
> when printf("%s\n",structure.feild); or printf(stdout,..) the program runs
> correctly
> but when fprintf(file_pointer,...) is used the program aborts with
> run time system error: malloc failed (or something damn close to it)
> this problem also occurrs with fputs(..file_pointer);
The problem is that when you first access a freshly opened stream, stdio
mallocs a buffer for it. If this malloc fails it reports a run time error.
There are a number of ways you can get around this.
1) Ensure your program has enough memory for the malloc to succeed.
2) Call setbuf or setvbuf immediately after opening the file
setbuf(file_pointer, 0); /* to turn file buffering off */
static my_buff[BUFSIZ]; /* BUFSIZ is declared in stdio.h */
setbuf(file_pointer, my_buff);
static my_buff[SOME_OTHER_SIZE]; /* A size of your choosing */
setvbuf(file_pointer, my_buff, _IOFBF, SOME_OTHER_SIZE);
Edward (enevill@acorn.co.uk)
Technical Details
Message-ID:
<19198@acorn.co.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!enevillReferences:
<1992Oct7.143034.11275@waikato.ac.nz>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!enevill From: enevill@acorn.co.uk (Edward Nevill) Newsgroups: comp.sys.acorn.tech Subject: Re: problem with fprintf & DTC Message-ID: <19198@acorn.co.uk> Date: 7 Oct 92 10:52:56 GMT References: <1992Oct7.143034.11275@waikato.ac.nz> Sender: enevill@acorn.co.uk Organization: Acorn Computers Ltd, Cambridge, England Lines: 26