Pop*_*eye 2 c file-handling dev-c++ null-pointer
我只是创建一个基本的文件处理程序.代码是这样的:
#include <stdio.h>
int main()
{
FILE *p;
p=fopen("D:\\TENLINES.TXT","r");
if(p==0)
{
printf("Error",);
}
fclose(p);
}
Run Code Online (Sandbox Code Playgroud)
这是给错误,我无法创建文件尝试重新安装编译器和使用不同的位置和名称的文件,但没有成功.我使用的是Windows 7,编译器是Dev C++版本5
从以下位置更改打开模式:
p=fopen("D:\\TENLINES.TXT","r");//this will not _create_ a file
if(p==0)
Run Code Online (Sandbox Code Playgroud)
对此:
p=fopen("D:\\TENLINES.TXT","w");//this will create a file for writing.
if(p==NULL) //If the file already exists, it will write over
//existing data.
Run Code Online (Sandbox Code Playgroud)
如果要将内容添加到现有文件,可以使用"a +"作为打开模式.
fopen的参考(更多开放模式,以及有关fopen函数族的其他信息)
| 归档时间: |
|
| 查看次数: |
4534 次 |
| 最近记录: |