600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > c语言程序无法打开文件 C语言fopen()总是提示无法正常打开文件

c语言程序无法打开文件 C语言fopen()总是提示无法正常打开文件

时间:2018-08-04 12:11:04

相关推荐

c语言程序无法打开文件 C语言fopen()总是提示无法正常打开文件

问题: 在windows系统命令行中运行编写的程序时,总是提示无法正常打开文件。

程序如下:

//reducto.c

//reduce the original file by 2/3

#include

#include

#include

#define LEN 100

int main (int argc, char *argv [])

{

FILE *in, *out;

int ch;

char name[LEN];

int count = 0;

if (argc < 2)

{

fprintf(stderr, “Usgae: %s filename\n”, argv[0]);

exit(EXIT_FAILURE);

}

if ((in = fopen(argv[1], “r”)) == NULL)

{

fprintf(stderr, “I couldn’t open the file \”%s\”\n”, argv[1]);

exit(EXIT_FAILURE);

}

strncpy(name, argv[1], LEN – 5);

name[LEN – 5] = ‘\0’;

strcat(name, ” .red”);

if ((out = fopen(name, “w”)) == NULL)

{

fprintf(stderr,”Can’t create output file.\n”);

exit(3);

}

while (ch = getc(in) != EOF)

if (count++ % 3 == 0)

putc(ch, out);

if (fclose(in) != 0 || fclose(out) != 0)

fprintf(stderr, “Error in closing files.\n”);

return 0;

}

visual stdio项目文件以及文本文件的位置

我将visuastdio 的项目文件以及准备用于打开的文本文件均放在桌面上,如下截图:

windows命令行运行的页面以及结果

回答

看看是不是你的系统隐藏了扩展名,实际上文件名是 exercise.txt.txt

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。