我不明白我做错了什么。我正在学习 C 很抱歉,如果这显然是错误的,但我正在尝试使用uthash http://uthash.sourceforge.net/制作股票及其价格的哈希图。但是当我将股票添加到哈希映射时,我收到上述错误。
我所做的就是从他们的网站上获取示例并运行它以确保它有效,一旦它按预期工作,我就更改了值以适应我的问题。在原始代码中,变量id
结构中是一个整数,但我将其更改为字符(而不是数字,我想使用股票代码作为键),然后我开始出现以下错误:
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin___strcpy_chk' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__inline_strcpy_chk' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
问题似乎出在此处的两行(87),即strcpy(s->id, user_id);
和 (89) 是:HASH_ADD_STR( users, id, s );
我如何使用这两个错误?我查了一下 strcpy,看起来需要 3 个项目,但是当我添加大小时,我仍然收到错误。
以下是我认为相关的部分的片段:
#include <stdio.h> /* gets */
#include <stdlib.h> /* atoi, malloc */
#include <string.h> /* strcpy */
#include "uthash.h"
struct my_struct {
char id; /* key */
float price;
UT_hash_handle hh; /* makes this structure hashable */
};
struct my_struct *users = NULL;
void new_stock(char *user_id, float price) {
struct my_struct *s;
s = (struct my_struct*)malloc(sizeof(struct my_struct));
strcpy(s->id, user_id);
s->price = price;
HASH_ADD_STR( users, id, s ); /* id: name of key field */
}
int main() {
printf("starting..");
new_stock("IBM", 10.2);
new_stock("goog", 2.2);
return 0;
}