from integer makes pointer_从没有使用strcpy的强制转换的整数生成指针(makes pointer from integer without a cast with st...

从没有使用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值