保存用C的fopen文件 [英] Save file with C fopen

查看:183
本文介绍了保存用C的fopen文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在C程序,但它不允许以节省C:\\ SomeDirectory \\ afile.txt

I did a program in C but it does not allow to save on c:\SomeDirectory\afile.txt

我用这样的:

FILE* m_hFile = fopen("c:\\SomeDirectory\\afile.txt", "a+t");
fprintf(m_hFile, "testing");
fclose(m_hFile);

为什么呢?是否有一个定义的文件夹,我可以在救?

Why that? Is there a defined folder I can save in?

SomeDirectory是previously创建。

SomeDirectory is previously created.

我使用Windows 7操作系统。

I'm using Windows 7 OS.

推荐答案

如果的fopen 遇到一个错误,它集错误号变量,指示发生了什么错误。您可以测试这一点,或者更简单,使用 PERROR 打印出的错误消息会告诉你哪里出了问题:

If fopen encounters an error, it sets the errno variable indicating what error occurred. You can test this, or even simpler, use perror to print out an error message that will tell you what went wrong:

FILE* m_hFile = fopen("c:\\SomeDirectory\\afile.txt", "a+t");
if (m_hFile == NULL) {
  perror("fopen");
}

这篇关于保存用C的fopen文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆