🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.acorn.tech
2 messages
2 total messages Started by shunger Wed, 07 Oct 1992 01:30
problem with fprintf & DTC
#487
Author: shunger
Date: Wed, 07 Oct 1992 01:30
7 lines
674 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);
Re: problem with fprintf & DTC
#220
Author: Edward Nevill
Date: Wed, 07 Oct 1992 10:52
26 lines
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)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads