I don't think we want to read a whole file into memory in the end (this method can stay though of course), so maybe split this in 2 methods. It's also possible to make this whole thing a class, then FILE *file; can be shared between all these methods without having to be passed around.. That way you can initialize it to NULL in the constructor and have every method return in the beginning if it's not a valid file descriptor...