I would like to know the address of an opened file with open function:
int fd = open("file" , O_RONLY);
now we have the fd of this opened file, if we need to read from it, we just type:
read(fd, buffer, size);
Example:
file : | H | E | L | L | O | | W | O | R | L | D |
if we read from that file 3 chars:
int fd = open("file" , O_RONLY);
read(fd, buffer, 3);
The cursor now here: | H | E | {L} | L | O | | W | O | R | L | D |
Question: So, how can I get the address of this {L}
char, or the address of the first char {H}
? I would like to know the address of this opened file without using the "FILE F = fopen"*
CodePudding user response:
i would like to know the address of this opened file without using the "FILE F = fopen"
There is no such thing. The file exists somewhere on disk, but it has no address in memory until you open and read some data from it.
What you do is read
the contents of the file into some buffer which you provide. That buffer has an address. The address of the 3rd character in that buffer is buffer 2
.
CodePudding user response:
I think you are making assumptions on how files work - and you should not. That is what the file operation functions are for. Whatever you try to do via that pointer, you need to find a way to do it via defined functions from libs.
CodePudding user response:
Ahh i have wrong, file don't have @ in 'RAM' Thanks