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 的项目文件以及准备用于打开的文本文件均放在桌面上,如下截图:

13f563292c292c0cd8dd9ae0da07639d.png

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

f80598891542c2147d3fd4c8e11da8fc.png

回答

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值