对不起,如果标题有点令人困惑.我正在做的是创建一个结构,如:
struct record
{
int value;
int key;
};
Run Code Online (Sandbox Code Playgroud)
然后使用typedef调用指针来记录"Item",如下所示:
typedef struct record* Item;
Run Code Online (Sandbox Code Playgroud)
基本上我正在跟踪Robert Sedgewick(第三版)在C语言中如何在C语言中完成它,如果有人碰巧有这本书的话.
我遇到的麻烦是从控制台读取一个值,然后将其分配给键.这就是我所拥有的,以及我得到的错误:
void setKey(Item *element, int x)
{
element->key = x;
}
void standInput(Item A[], int length)
{
int i;
int x;
for(i = 0; i < length; i++)
{
printf("Enter a value for spot %i: ", i+1);
scanf("%d", &x);
setKey(A[i], x);
}
}
gcc Item.h
Item.h:33:6: warning: conflicting types for ‘setKey’
Item.h:23:3: note: previous implicit declaration of ‘setKey’ was here
Run Code Online (Sandbox Code Playgroud)
如果我能在正确的方向上轻推,我真的很感激.当Item只是简单的整数时,我得到了这个任务的程序,但现在我正在尝试使用Item-> Key,我有点失落:)谢谢!
如果有人需要我认为不必要的代码的任何其他部分,我会在看到请求后立即发布.
修订:我将setKey函数移到了standInput之上,因此编译错误消失了.我得到的是一个段错误,所以我仍然分配错误:)