从不兼容的指针类型错误分配

时间:2017-03-08 01:54:04

标签: c pointers

这些是我的结构。想想C中的链接列表。

countriesCircles

现在,我的文件中有一个搜索功能,

/**
 * The WordNode struct is used to represent a node in a linked list of
 * words. It is defined in this file because it is used only within this
 * file. It is used only as part of the implementation of a word set.
 */
typedef struct WordNode WordNode;
struct WordNode {
  int       freq;   // The frequency of the the word.
  char     *word;   // The word itself.
  WordNode *next;   // The next word node in the list.
};

/**
 * A WordSet struct is used to represent a "set". We are implementing a set as
 * a linked list of WordNodes.
 */
struct WordSet {
  int       size;   // The number of elements in the set.
  WordNode *head;   // The starting node in the set.
};

我收到警告:来自不兼容指针类型的分配错误p = wset-> head

根据我的理解,** p表示这是指向指针的指针。因此,当我将p初始化为p = wset-> head时,我基本上将指针p初始化为指针头,因此它是指向指针的指针。为什么我仍然得到不兼容的指针类型错误?

我也对我在WordNode中引用内容的方式感到有些困惑。例如,当我执行类似(* p) - >接下来的操作时,这是访问“下一个”指针的正确方法吗?

0 个答案:

没有答案