First off you do realize that printf writes to stdout, right? You should be opening your files before you process the file. The reason for this is because it is possible that you are only allowing the file to be open under a condition that is not being met. Also you may be opening it more than once (unlikely though, your problems would be much different). You could also write your errors to stderr. And if you desperately need stderr dumped into a file you can always do this:
Of course the skeleton code there omits error handling.
FILE *my_error_log = freopen("error.log", "w", stderr);
//the next two statements do the same thing