【发布时间】:2015-01-30 18:27:21
【问题描述】:
作为一个更大项目的一部分,我正在尝试编写一个 C 函数,该函数在已实现的排序链表中搜索结构 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
【问题讨论】: