1

File streams are always acceded through pointers and they are always pre-created. But is it possible to create a file stream inside the program as an object that holds space in memory without using an external file?

My first thought was to declare a FILE * pointer then allocate memory for a FILE object using malloc():

FILE *fileStream = malloc(sizeof(FILE));

but I guess this is not right.

How can I do it the right way so I can work with fileStream using the I/O functions like fprintf() and fscanf() ...

rullof
  • 7,124
  • 6
  • 27
  • 36

1 Answers1

0

There is no support in C itself for this. You will need to use platform-specific means. If on Unix, you could combine memmap and fdopen, for instance. For other platforms, see the platform documentation.

Magnus Reftel
  • 967
  • 6
  • 19