首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

请教各路大神,为什么两种方法都不能读写文件

2012-09-19 
请问各路大神,为什么两种方法都不能读写文件#include stdio.h#include stdlib.hint main(){FILE *pf,*

请问各路大神,为什么两种方法都不能读写文件
#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *pf,*pn;
char ch;
if((pf=fopen("test.txt","r+"))==NULL)
{
printf("1.The file can not be open!!!\n");
exit(0);
}
printf("success\n");
if((pf=fopen("done.txt","w+"))==NULL)
{
printf("2.The file can not be open!!!\n");
exit(0);
}
printf("success\n");
/*第一种方法
  while((ch=fgetc(pf))!=EOF)
{
printf("%c",ch);
fputc(ch,pn);
}
*/
while(!feof(pf))//第二种方法
{
ch = fgetc(pf);
fputc(ch,pn);
}
close(pf);
close(pn);
}

[解决办法]
都写成了pf了,第2个应该是pn的。
if((pf=fopen("test.txt","r+"))==NULL)
if((pf=fopen("done.txt","w+"))==NULL)

热点排行
Bad Request.