问题:运行在windows系统命令行上创建的程序时,系统总是提示您文件无法正常打开。
步骤如下。
//reducto.c
//reduce the original file by 2/3
#包含
#包含
#包含
#define LEN 100
(intmain(intargc,char *argv [] ) ) ) ) ) ) ) ) ) ) )
{
FILE *in,*out;
int ch;
char name[LEN];
int count=0;
是if(argc2)
{
fprintf(stderr、“usgae : % s文件名称 n”、argv[0];
exit(exit_failure;
}
if((in=fopen ) argv[1],“r”) )==NULL ) )
{
fprintf(stderr," icouldn’topen the file" % s\ ",argv[1];
exit(exit_failure;
}
strncpy(name,argv[1],len5 );
name [ len5 ]=‘ 0’;
strcat(name,”. red”;
if () out=fopen(name,“w”)==NULL ) )
{
frintf(stderr,”can’tcreateoutputfile. n”;
退出(3;
}
wile(ch=getc(in )!=EOF )
if (计数%3==0) )
putc(ch,out );
if(fclose(in )!=0|||fclose(out )!=0)
frintf(stderr,“关闭文件中的错误.n”
返回0;
}
visual stdio项目和文本文件的位置
将visuastdio项目文件和准备打开的文本文件放在桌面上,如下图所示。
在windows命令行上运行的页面和结果
回答
看看你的系统是否隐藏了扩展名。 实际上文件名为exercise.txt.txt