fopen

Hi!

Is it fine to have f_output = fopen("output.txt", "w");

without the:

if(f_output == NULL){
printf("\nFile input.txt was not found!!");
printf("\nFind the file and select again.\n");

break;
}

?

since it is for writing it would create a file named output.txt right?
so theres no need for if (f_ouput == NULL) right?
closed account (DSLq5Di1)
There is a multitude of reasons for fopen to fail:-
http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html#tag_03_176_05
I think it doesnt answer my question. Can you just tell me if what I will be doing is fine?
You have mis-read a direct answer to your question.
You need to check, because there are many reasons that fopen() can fail, even for creating/overwriting a file.
The check if(f_output == NULL) is important for the reasons already give to you. What you do then is up to you. The error message in your example is inappropriate because you are creating a file rather than looking for one. But you should still do something if opening the file fails.
Thanks for the answers.

Ok I'll just put an error "File creating failed".

Thanks!
Topic archived. No new replies allowed.