Using Linux system calls open and read. The read call accepts 3 parameters
read(File descriptor, Buffer array, Size of the buffer array);
My question is related to the argument #3. Suppose I have multiple text files that I want to read into my buffer array. But as far as I know C doesn’t have something like Vector or ArrayList or any other structure with a dynamic size.
Is there an easy way to calculate the size of the file so I know how much space should I allocate for my char array?
You could also
stat()the file to determine its size and then call mmap() on it. Your file will appear as an “array” without the need tomalloc()memory.