There's something called memory mapped file, but this apart, you can achieve what you want (if I understood it correctly) simply opening the file and loading it into a buffer (which is by the way a common way of reading data from files).
Once in memory, you access the first byte with *buf
, the second with *(buf+1)
and so on; or, usually better since clearer, with buf[0]
, buf[1]
and so on.
Why you can't if you don't use a memory mapped file? Since what you have when you open a file in C (using fopen
) is an opaque pointer (i.e. a pointer pointing to data unnknown to you, you must consider it as a "concept" rather than actual data you can read) allowing other functions (fread, fwrite, fseek, and so on) to "operate" on that file you opened, but that pointer does not "contain" the bytes of the file. It is called sometimes handler for a reason: it makes it possibile to "handle" the file.
Using that opaque pointer FILE*
, you can read bytes from that file in memory, then you can process the data in memory.