C 使用typedef结构时出现未知类型错误

C 使用typedef结构时出现未知类型错误,c,struct,typedef,C,Struct,Typedef,我知道有很多问题要问,但我已经看了很多问题,我仍然不知道问题出在哪里。这一定是一些简单的错误,但我已经将这个结构声明和使用与我在同一个项目中使用的另一个结构声明和使用进行了比较(没有错误),它们在我看来是一样的 我在trie.h中声明了这个结构: #ifndef TRIE_H #define TRIE_H #include "fw.h" #include "linked.h" #define ALPHABET_SIZE 26 typedef struct T_node { /* nu

我知道有很多问题要问,但我已经看了很多问题,我仍然不知道问题出在哪里。这一定是一些简单的错误,但我已经将这个结构声明和使用与我在同一个项目中使用的另一个结构声明和使用进行了比较(没有错误),它们在我看来是一样的

我在trie.h中声明了这个结构:

#ifndef TRIE_H
#define TRIE_H

#include "fw.h"
#include "linked.h"

#define ALPHABET_SIZE 26

typedef struct T_node
{
   /* number of times this word has been found 
      (stored at end of word) */
   int freq;
   /* is_end is true if this T_node is the end of a word 
      in which case it */
   int is_end;
   /* each node points to an array of T_nodes
      depending on what letter comes next */
   struct T_node *next[ALPHABET_SIZE];
} T_node;

int add_word(T_node *root, char *word);
T_node *create_node(void);
void max_freqs(T_node *root, int num, List *freq_words, char *word,
               int word_len, int i);
void free_trie(T_node *root);

#endif
我在fw.h中使用它:

#ifndef FW_H
#define FW_H

#include <stdio.h>

#include "trie.h"

#define FALSE 0
#define TRUE 1

int read_file(FILE *in, T_node *root);
char *read_long_word(FILE *in);

#endif
编辑:我不认为这是一个重复的链接问题。如果您查看上面的答案,那么所提供的结构似乎与我的T_节点当前使用的格式相同。此外,我没有收到与该问题相同的错误。

错误消息

在trie.h:4:0中包含的文件中,
摘自trie.c:5:
fw.h:11:25:错误:未知类型名称T_节点
int read_文件(文件*in,T_节点*root);
^
表示
trie.c
包括
trie.h
,其中包括
fw.h

但我们也看到,
fw.h
包括
trie.h
。所以我们有一个完整的循环



如果可能,使用前向声明的struct
int read_文件(file*in,struct T_node*root)
并从
fw.h
中删除
trie.h
include

您可以发布َa?@gzh吗?它不是它的副本,请注意,在这种情况下,下一个[ALPHABET_SIZE]是
struct_node*,这是正确的。@IharobAlAsimi好的,我放了完整的头文件。“我不认为它们相关,但它们可能有用。”dumbitdownjr您的问题在下面得到了回答。看一看。您需要确保一个文件只包含一次。实现这一点的一个简单方法是使用所谓的include-guard,只需
#ifndef MY_FANCY_HEADER_文件
,然后在下一行
#定义MY_FANCY_HEADER_文件
和文件末尾
#endif
。这样,即使您多次包含该文件,编译器也只会包含其内容,直到您定义
MY_FANCY_HEADER_file
宏,因此它只包含一次。问题中的
fw.h
根本不使用
t_节点
,并且在错误消息中没有行。看起来您意外地包含了
linked.h
?无论哪种方式,如果在
trie.h
中包含
fw.h
,那么在
fw.h
中包含之后定义的内容是没有意义的,因为它不会看到它。所以这是不允许的?我需要trie.c中的fw.h,我也需要fw.h中的trie.h。这是否意味着我应该将它们合并到一个头文件中?您必须组织代码,这样您就不会得到循环包含。您不需要结构的完整声明就可以将指向它的指针作为参数传递。为此,使用前向声明
struct_节点就足够了
In file included from trie.h:4:0,
             from trie.c:5:
fw.h:11:25: error: unknown type name T_node
 int read_file(FILE *in, T_node *root);
                         ^