I think making this whole thing a class will greatly benefit the code. Then FILE *file; can be shared between all these methods without having to be passed around.. That way one can initialize it to NULL in the constructor and have every method return in the beginning if it's not a valid file descriptor...