I'm trying to output some string on a txt file by using c program
however, I need to see if the I have the permission to write on the txt file, if not, I need to print out the error message? However, I don't know how to detect if I successfully open a file or not, could someone help me about this? thanks
The code is like this
File *file = fopen("text.txt", "a");
fprintf(file, "Successfully wrote to the file.");
//TO DO (Which I don't know how to do this)
//If dont have write permission to text.txt, i.e. open was failed
//print an error message and the numeric error number
Thank you for anyone helps, thanks a lot