小编Pen*_*Ren的帖子

如何在c中打开或不打开文件

我正在尝试使用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
Run Code Online (Sandbox Code Playgroud)

感谢任何人的帮助,非常感谢

c

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

c ×1