作为一个更大项目的一部分,我正在尝试编写一个 C 函数,该函数在已实现的排序链表中搜索 struct 中的值olnode
。但是,我收到了一些错误。我是 C 新手,我正在为指针和双指针以及何时使用什么而苦苦挣扎,所以我认为这是问题的一部分,但我不确定如何解决这个问题。包括所有必要的标题。这是在使用 cc 作为编译器的 Minix 2.0.4 上。
我可以提供任何额外的必要代码;因为我不熟悉 C,所以我不确定我需要展示多少,所以我提供了我认为需要的东西,仅此而已。
全局代码(标题除外):
#define POOLSZ 53
struct olnode {
int eventnr;
int eventfq;
struct olnode *next;
};
typedef struct olnode olnode;
olnode pool[POOLSZ];
olnode *avail; /* points to first available node */
返回错误的函数(搜索传递的 int,完成后*current
应该是olnode
保存当前值的函数):
void
srchfreq(olnode *list, int xfrequency, olnode **current)
{
olnode *previous, *newnext;
while(current->eventfq > xfrequency) {
*previous = ¤t;
*newnext = current->next;
*current = *newnext;
}
}
srchfreq()
(在不同的函数中)的函数调用:
/* *list points to the first node in the list
(*current).eventfq is the value being searched for
*/
srchfreq(*list, (*current).eventfq, ¤t);
错误(行号被编辑为相对于srchfreq()
上面给出的行):
line 6: illegal use of selector eventfq
line 7: cannot convert pointer to struct
line 8: illegal use of selector next
line 8: cannot convert pointer to struct
line 9: cannot convert struct to pointer