Wednesday, September 26, 2018

c - stdio.h function fopen() error scenarios in "w" mode

I have experimented with fopen() in writing mode to try and see if it ever returns NULL. I tried opening multiple files of the same name, and inputting invalid file names. Obviously, fopen() does not care about recycled names, as it just opens a fresh file every time and overwrites any existing data. Inputting invalid file names merely caused a command line error. None of the test cases I tried caused fopen() to return NULL.



This is never something that I have encountered in everyday programming, but I always follow the philosophy of never assuming that a file will always be successfully opened. Thus, I always error-check every file pointer, regardless of what I am doing with the file.



But for full awareness about file I/O, I found myself curious: What are the scenarios, if any, in which fopen() will return NULL in "w" mode?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...