0

I'm using a system function which writes the output information into a stream of file pointer.

func(FILE *__fp)

I need to use this information in my program rather than printing this out to a file. For that I thought of creating a tmpfile() and writing to it then reading back from it. But is there a better way to get this information?

nithinj
  • 83
  • 3
  • 9
  • https://stackoverflow.com/questions/3481157/string-stream-in-c is probably relevant – hyde Sep 14 '18 at 06:02

1 Answers1

1

There are OS-specific solutions to writing to a memory buffer instead of a file, like for example the POSIX fmemopen or open_memstream (both which should be very useful considering your linux tag).

You can also change the internal buffer to your own with setvbuf.


On an unrelated note: Symbols starting with a leading underscore and followed by another underscore (like for example your __fp argument) are reserved. Such symbols may only be used by "the implementation", i.e. the compiler and library.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621