0

I want to perform file operations(fread, fwrite... etc) with a array(char*, but if is possible with any type also will be good).

I know that i can do it with sprintf and sscanf, but i no want use these. Why? i are writing a Intel 8080 emulator, and i are writing the RAM, so i will read more that individual chars, read ints and so on.

I want use fread and fwrite because you can give them the size of the elements, with sprintf and sscanf you can use format, but i must write code for every type.

At this moment i don't have any issues, nor much code, i only want know if my question has a answer, else i will see how convert a array of char to other data type...

Resuming, i can use char* as FILE* ?.


Sorry for my bat English...

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
ZarWare
  • 25
  • 2
  • For a 8080 emulator, I would just use a 64K file, and mmap() it. – wildplasser Jun 28 '17 at 23:03
  • Can you please provide some code, even pseudo-code, which demonstrates how you want to call the operations and give examples of input and desired output? – Stephan Lechner Jun 28 '17 at 23:03
  • 1
    Just a well meant recommendation: if you ask such a question, I somehow doubt you are fit to write an CPU emulator. Start with a less challenging project, e.g. work through a good C book about modern C (not K&R, not C90 - learn C99, better standard C11). Any textbook will explain the file functions and all other facilities you need. – too honest for this site Jun 28 '17 at 23:07
  • his question is not, how to write a char array to a file. His question is 'can I use a memory array as a file' A totally different question - take a look at http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html – pm100 Jun 29 '17 at 15:46
  • thats fmemopen. see https://stackoverflow.com/questions/5135854/make-a-file-pointer-read-write-to-an-in-memory-location – pm100 Jun 29 '17 at 15:48

0 Answers0