c - 错误: request for member ‘txt’ in something not a structure or union

标签 c function file if-statement while-loop

抱歉,当我尝试编译代码时,我的代码出现问题,并且我不明白需要解决什么错误:

“6:26:错误:requestformember‘txt’不是结构或 联盟”

                fichero = fopen(fichero.txt,"r");

谁能帮帮我

我给你留下我的代码:

#include <stdio.h>
int calcular(char nombre[]){
  FILE *fichero; int contar, maximo = 0;
  char caracter;
  fichero = fopen(fichero.txt,"r");
        if(fichero == NULL)
         printf("ERROR de Apertura");
        else{
             while(!feof(fichero)){
                 fscanf(fichero, "%c", & caracter);
                 if(caracter == '/n'){
                   if(contar > maximo)
                      maximo = contar;
                      contar = 0;
                      fclose(fichero);        
                      fclose(salida);
                 }
             }
             contar++;
        }
        return(linea);
}

最佳答案

您将字符串文字 fichero.txt 传递给 fopen()(不带双引号),欺骗编译器认为 fichero 是一个结构体,而 txt 是该结构体的成员。

尝试:

fopen("fichero.txt", "r");

关于c - 错误: request for member ‘txt’ in something not a structure or union,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975229/

相关文章:

java - 使用Spring在项目目录中存储文件

C 程序接受三个整数并查看它们是否构成三角形和直角

c - 文本被 append 在文件的开头而不是文件的末尾

C++,在尝试创建类 : error: no ‘void media::*()’ member function declared in class ‘media’ 时收到此消息

c++ - C++从文件中读取对象

c - stat.h 在 Linux 中不可用?

c++ - 能否将代码字符串传递到 C\C++ 宏中?

c - 为什么输出字符串显示我从未写过的数据?

Python加密函数和全局变量

python:无法从用户定义的函数返回 pandas 数据框(可能是用户错误)