#include <stdio.h> #include <stdlib.h> void main(int argc,char*argv[]) { FILE *fp1,*fp2; char c,ch; long j; char *in_file,*out_file; if(argc!=3) { printf("\ninput the in_file:"); gets(in_file); printf("\ninput the out_file"); gets(out_file); } else { strcpy(in_file,argv[1]); strcpy(out_file,argv[2]); }
if(!(fp1=fopen(in_file,"rb"))) {printf("\ncannot open the in_file"); exit(1); } fp2=fopen(out_file,"wb"); if(!fp2) { printf("\ncannot open the out_file"); exit(1); } printf("\ninput the passwd:"); scanf("%i",&j); srand(j); /*初始化随机函数生成器*/ ch=fgetc(fp1); while(!feof(fp1)) { c=rand(); ch=ch^c; fputc(ch,fp2); ch=fgetc(fp1); } fclose(fp1); fclose(fp2); printf("\nlock file successfully!"); exit(0); } 编译运行时,说“cannot open the out_file” 可如果要加入两个没有什么作用的输出语句就可以拉 比如:
[此贴子已经被作者于2005-3-31 13:31:35编辑过]
----------------解决方案--------------------------------------------------------
#include <stdio.h> #include <stdlib.h> void main(int argc,char*argv[]) { FILE *fp1,*fp2; char c,ch; long j; char *in_file,*out_file; if(argc!=3) { printf("\ninput the in_file:"); gets(in_file); /*********在这加一个getch() 也能运行*******************/ printf("\ninput the out_file"); gets(out_file); } else { strcpy(in_file,argv[1]); strcpy(out_file,argv[2]); }
printf("\nin_file is %s",in_file); /***** 加入这两句就可以拉*************/ printf("\nout_file is %s",out_file); if(!(fp1=fopen(in_file,"rb"))) {printf("\ncannot open the in_file"); exit(1); } fp2=fopen(out_file,"wb"); if(!fp2) { printf("\ncannot open the out_file"); exit(1); } printf("\ninput the passwd:"); scanf("%i",&j); srand(j); /*初始化随机函数生成器*/ ch=fgetc(fp1); while(!feof(fp1)) { c=rand(); ch=ch^c; fputc(ch,fp2); ch=fgetc(fp1); } fclose(fp1); fclose(fp2); printf("\nlock file successfully!"); exit(0); } 请问这时怎么回事?
[此贴子已经被作者于2005-3-31 13:35:00编辑过]
----------------解决方案--------------------------------------------------------
可以运行啊 我怎么可以运行呢?
----------------解决方案--------------------------------------------------------
#include <stdio.h> #include <stdlib.h> void main(int argc,char*argv[]) { FILE *fp1,*fp2; char c,ch; long j; char *in_file,*out_file; if(argc!=3) { printf("\ninput the in_file:"); gets(in_file); printf("\ninput the out_file"); gets(out_file); } else { strcpy(in_file,argv[1]); strcpy(out_file,argv[2]); }
if(!(fp1=fopen(in_file,"rb"))) {printf("\ncannot open the in_file"); exit(1); } fp2=fopen(out_file,"wb"); if(!fp2) { printf("\ncannot open the out_file"); exit(1); } printf("\ninput the passwd:"); scanf("%i",&j); srand(j); /*初始化随机函数生成器*/ ch=fgetc(fp1); while(!feof(fp1)) { c=rand(); ch=ch^c; fputc(ch,fp2); ch=fgetc(fp1); } fclose(fp1); fclose(fp2); printf("\nlock file successfully!"); exit(0); } 指针只能赋值,不能用那个函数!
----------------解决方案--------------------------------------------------------
斑竹的不是和我的一样吗
你能给我解释一下 为什么 我加个输出语句就可以运行了
我以前从来没碰到国这种情况
----------------解决方案--------------------------------------------------------