我正在尝试使用c程序在txt文件上输出一些字符串
但是,我需要查看我是否有权在txt文件上写入,如果没有,我需要打印出错误信息?但是,我不知道如何检测我是否成功打开文件,有人可以帮我解决这个问题吗?谢谢
代码是这样的
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
感谢任何人的帮助,非常感谢
c ×1