C:散列 table 上的指针类型不兼容
C: Incompatible pointer type on hash table
我正在尝试实现一个散列 table,一切都很好,直到我在 main 中定义 "idx"(这对我来说是必须的)。现在,因为 "idx" 不再是全局变量,我必须在调用函数时将它用作参数,并且我收到以下消息:"warning: passing argument 3 of 'index_createfrom' from incompatible pointer type"。
在这种情况下调用函数的正确方法是什么?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE_HASH_MAP 10
struct index{
char* info;
int line[30];
struct index *next;
};
typedef struct index Index;
int index_createfrom(FILE* pointerToText, FILE* pointerToKey, Index **idx)
{
return 1;
}
int main() {
Index* idx[SIZE_HASH_MAP] = {NULL};
FILE *pointerToText = fopen("text.txt", "r");
FILE *pointerToKey = fopen("keyFile.txt", "r");
int a = index_createfrom(pointerToText, pointerToKey, &idx); // warning here.
}
idx
是一个 Index**
,所以 &idx
是一个指向 Index**
(也就是说 Index***
)的指针。
你应该传递 idx
而不是 &idx
。
我正在尝试实现一个散列 table,一切都很好,直到我在 main 中定义 "idx"(这对我来说是必须的)。现在,因为 "idx" 不再是全局变量,我必须在调用函数时将它用作参数,并且我收到以下消息:"warning: passing argument 3 of 'index_createfrom' from incompatible pointer type"。
在这种情况下调用函数的正确方法是什么?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE_HASH_MAP 10
struct index{
char* info;
int line[30];
struct index *next;
};
typedef struct index Index;
int index_createfrom(FILE* pointerToText, FILE* pointerToKey, Index **idx)
{
return 1;
}
int main() {
Index* idx[SIZE_HASH_MAP] = {NULL};
FILE *pointerToText = fopen("text.txt", "r");
FILE *pointerToKey = fopen("keyFile.txt", "r");
int a = index_createfrom(pointerToText, pointerToKey, &idx); // warning here.
}
idx
是一个 Index**
,所以 &idx
是一个指向 Index**
(也就是说 Index***
)的指针。
你应该传递 idx
而不是 &idx
。