收到一份;“成员不在结构中”;C中的错误

收到一份;“成员不在结构中”;C中的错误,c,compiler-construction,struct,C,Compiler Construction,Struct,因此,我正在为一个assignment编写一个程序,该程序从固定格式的文本文件(目录的反向索引,格式如下)中提取单词: <list> a // word found in indexed files 0: 1 // in the format <file descriptor>: <number of occurences in file> 1: 1 </list> <list> b 0:1 </list&

因此,我正在为一个assignment编写一个程序,该程序从固定格式的文本文件(目录的反向索引,格式如下)中提取单词:

<list> a // word found in indexed files
    0: 1 // in the format <file descriptor>: <number of occurences in file>
    1: 1
</list>
<list> b
    0:1
</list>
<file>
    0: file1.txt //in the format <file descriptor>: <full file path>
    1: testdir/file2.txt
</file>
因此,每当我尝试编译时,我都会收到一大堆错误。我似乎遇到的主要错误是:

User@root:~/test$ gcc -o s search.c
search.c: In function ‘searchthroughfileandcreatenodes’:
search.c:38:22: warning: cast to pointer from integer of different size
search.c:43:17: error: request for member ‘next’ in something not a structure or union
search.c:44:17: error: request for member ‘next’ in something not a structure or union
search.c:45:17: error: request for member ‘next’ in something not a structure or union
search.c:46:17: error: request for member ‘next’ in something not a structure or union
search.c:47:17: error: request for member ‘next’ in something not a structure or union
search.c:48:32: error: request for member ‘next’ in something not a structure or union
search.c:49:24: error: request for member ‘wordtok’ in something not a structure or union
search.c:49:5: warning: passing argument 2 of ‘strcpy’ from incompatible pointer type
/usr/include/string.h:128:14: note: expected ‘const char * __restrict__’ but argument is of type ‘char **’
search.c:54:18: error: request for member ‘file’ in something not a structure or union
search.c:55:18: error: request for member ‘file’ in something not a structure or union
search.c:56:18: error: request for member ‘file’ in something not a structure or union
search.c:57:18: error: request for member ‘file’ in something not a structure or union
search.c:57:41: error: request for member ‘next’ in something not a structure or union
search.c:67:17: error: request for member ‘next’ in something not a structure or union
search.c:68:17: error: request for member ‘next’ in something not a structure or union
search.c:69:17: error: request for member ‘next’ in something not a structure or union
search.c:70:30: error: request for member ‘next’ in something not a structure or union
我尝试过如何声明我的结构,如何创建我的列表,但我似乎无法找出导致这些错误的原因。我知道有很多代码需要筛选,但如果有人能指出我做错了什么,我将不胜感激


谢谢。

hashtok
是指针。所以
temphashhead
是指向指针的指针。所以你必须说
(*temphashhead)->next


(这也是完全没有意义的,因为
temphashhead
只指向一个局部变量,而且您不需要重新放置指针。所以只需说
hashtok temphashhead=hashhead;

hashtok
是一个指针。所以
temphashhead
是指向指针的指针。所以您必须说
(*temphashhead)->下一步


(这也是完全没有意义的,因为
temphashhead
只指向一个局部变量,而且你永远不需要重新放置指针。所以只要说
hashtok temphashhead=hashhead;

这就是为什么像这样使用typedef是不好的。它们隐藏了意图。当你需要时键入
*
并不难

跳出来的是:

int searchthroughfileandcreatenodes(fplist fphead, hashtok hashhead, 
                                    char * filename)
hashtok
struct Hashtoken*

然后执行以下操作:

hashtok * temphashhead = &hashhead;
如果去掉typedefs,它是:

sturct Hashtoken **temphashhead = &hashhead;
现在您有一个指向指针的指针,然后尝试通过以下方式将其用作指针:

temphashhead->next

编译器错误接踵而至。

这就是为什么像这样使用typedef是不好的。它们隐藏了意图。在需要时键入
*
并不难

跳出来的是:

int searchthroughfileandcreatenodes(fplist fphead, hashtok hashhead, 
                                    char * filename)
hashtok
struct Hashtoken*

然后执行以下操作:

hashtok * temphashhead = &hashhead;
如果去掉typedefs,它是:

sturct Hashtoken **temphashhead = &hashhead;
现在您有一个指向指针的指针,然后尝试通过以下方式将其用作指针:

temphashhead->next

<>编译错误随之发生。

我有一个预感,C++中的这一点将会非常简单……我完全同意……最难的部分是试图说服我的教授,这是一个直觉,我知道Type是让我的头受伤了。他是掌握无用技能的艺术教授吗?你是专门研究系统编程还是嵌入式系统?哈哈,讽刺的是,我专门研究信息安全。学校说我必须学习系统编程,但是我有一个预感,在C++中这将是非常简单的……我完全同意…困难的部分是试图说服我的教授这一点=p。我有一种预感,typedefs让我头疼。他是掌握与现实世界脱钩的无用技能的教授吗?:-)说真的,你是专门研究系统编程还是嵌入式系统?哈哈,讽刺的是,我专门研究信息安全。学校说我必须学习系统编程,不过你刚上了两个月的课,哈哈。谢谢!:)很高兴我能帮忙。您可以使用现有的typedef并相应地取消引用,但我个人会将它们更改为非指针,然后在需要时显式使用
*
;e、 g.
typedef结构HashToken hashtok
hashtok*hashhead
Ohhhhhhh哇,你刚上了两个月的课,哈哈。谢谢!:)很高兴我能帮忙。您可以使用现有的typedef并相应地取消引用,但我个人会将它们更改为非指针,然后在需要时显式使用
*
;e、 g.
typedef结构HashToken hashtok<代码>hashtok*hashhead