C具有多个句点的文件名

  • 本文关键字:句点 文件名 c fopen
  • 更新时间 :
  • 英文 :


简单问题。

当我尝试打开一个名为text.txt的文件时,它可以正常工作。

但是,如果我将文件重命名为text.cir.txt,就会出现错误。

我能做些什么来修复它?

FILE *fd;
char nome_fich[] = "text.cir.txt";
int x;
fd = fopen("text.cir.txt", "r");
if (fd == NULL)
{
printf("ERROR");
}
else
{
while ((x = fgetc(fd)) != EOF)
{
printf("%c", x);
}
fclose(fd);
}

以下建议的代码:

  1. 干净地编译
  2. 执行所需的功能
  3. 正确检查和处理错误

现在,提出的代码:

#include <stdio.h>    // FILE, fopen(), perror(), printf()
#include <stdlib.h>   // exit(), EXIT_FAILURE
int main( void )
{
FILE *fd = fopen( "text.cir.txt", "r" );
if ( !fd )
{
perror( "fopen failed" );
exit( EXIT_FAILURE );
}
// implied else, fopen successful
int x;
while ((x = fgetc(fd)) != EOF)
{
printf("%c", x);
}
fclose(fd);
}

当针对任何.txt文件运行时,它将执行所需的操作。

注意:我运行的是Linux版本18.04

最新更新