File Pointers in C
25/11/2025
I won't be following any particular order for this series. File pointers are probably not what you learn in your first class of C Programming 101. But this is more of a notebook than a tutorial, so if you don't know what pointers, structs, or functions are, you're probably in the wrong place.
File pointers are probably the only thing I got from the intro class I took that seemed like magic to me. After all, in my mind, external files are more related to the operating system than to any specific application or executable binary, so I didn't know how a programming language could have access to them. Add to this the fact that a bunch of new technical terms were thrown at me, like file descriptors, buffers, and modes of access, and you probably understand why to me, this seemed like a built-in function from Python more than C.
Fast forward to earlier today when I was writing a library for file manipulation, and decided on a whim to learn more about the file stream functions. Instead of doing the usual and looking up how to use fopen(), I decided on a whim to look it up in the book. All the better for it, because it clearly explains how external files are dealt with in C in a single paragraph:
The rules are simple. Before it can be read or written, a file has to be opened by the library function
fopen.fopentakes an external name likex.cory.c, does some housekeeping and negotiation with the operating system (details of which needn't concern us), and returns a pointer to be used in subsequent reads or writes of the file.This pointer, called the file pointer, points to a structure that contains information about the file, such as the location of a buffer, the current character position in the buffer, whether the file is being read or written, and whether errors or end of file have occurred.
There it is. That's all a file pointer is. It just points to a struct that stores information about the external file, and it does that by talking to the operating system. Exactly what I was confused about.