从没有使用strcpy的强制转换的整数生成指针(makes pointer from integer without a cast with strcpy)
我无法弄清楚我做错了什么。 我正在学习C很抱歉,如果这显然是错误的,但我正在尝试使用uthash来制作股票及其价格的哈希图。 但是当我向哈希地图添加股票时,我得到了上述错误。
我所做的是从他们的网站上获取示例并运行它以确保它工作,一旦它按预期工作我改变了值以适应我的问题。 在原始代码中,结构中的变量id是一个整数,但我将其更改为char(而不是数字,我想使用股票代码作为键),然后我开始出现以下错误:
../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 /* gets */
#include /* atoi, malloc */
#include /* 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