返回信息流在机房还能运行的程序,为什么回来放到自己的电脑上就打不开文件了,纠结死了~~~~~
这是一条镜像帖。来源:北邮人论坛 / cpp / #37185同步于 2010/3/28
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
求助:file could not be opened
irean
2010/3/28镜像同步13 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
【 在 irean 的大作中提到: 】
: 在机房还能运行的程序,为什么回来放到自己的电脑上就打不开文件了,纠结死了~~~~~
打开文件用的是什么函数?如果是用Windows api 那么在CreateFile或者OpenFile之后,调用GetLastError,这个函数会返回一个错误代码。在msdn里查查这个错误代码指代的原因。
根据个人经验,文件打开错误可能原因是文件路径不正确,或者权限不够。建议搂住好好检查一下参数
【 在 jokerlee 的大作中提到: 】
: 竟然敢用校长大人的照片做头像,小心把你关进小黑屋
用偶像当头像不犯罪啊[em16]和谐社会嘛 注重的是和谐
我贴代码吧,就是很纠结的上机作业,需要去除注释并存入另一个文件中,谢谢
#include <stdio.h>
#include <string.h>
char ch[10000];
main()
{
int i;
FILE *cfPtr1,*cfPtr2;
if ( (cfPtr1=fopen("clients.dat1","r"))==NULL )
printf("File could not be opened\n");
if ( (cfPtr2=fopen("clients.dat2","w"))==NULL )
printf("File could not be opened\n");
else{
while(!feof(cfPtr1))
{
label:
fgets(ch,sizeof(ch),cfPtr1);
for(i=0;i<strlen(ch);i++)
{
label2:
if(ch[i]!='/')fputc(ch[i],cfPtr2);
else
{
if(ch[i+1]=='/'){fputc('\n',cfPtr2);goto label;}
else if(ch[i+1]=='*')
{
for(;!(ch[i-1]=='*'&&ch[i]=='/');i++)
{
if(ch[i]=='\0'){fgets(ch,sizeof(ch),cfPtr1);i=0;}
}
goto label2;
}
}
}
}
}
fclose(cfPtr1);
fclose(cfPtr2);
}