I can't figure out what I'm doing wrong. I am learning C so sorry if this is obviously wrong, but I'm trying to use uthash to make a hash map of stocks and their prices. But when I add stocks to my hash map, I get the above error.
What I did was take the example from their site and ran it to make sure it worked, once it worked as expected I changed the values to fit my problem. In the original code, the variable id
in the struct was an integer but I changed it to a char(instead of number, I wanted to use the stock ticker as the key), then I started to the following errors:
../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
The problem seems to be with two lines here(87) which is strcpy(s->id, user_id);
and (89) which is: HASH_ADD_STR( users, id, s );
How am I using both of these wrong? I looked strcpy up and it looks like it takes 3 items, but when I add the size I still get errors.
Here's a snippet of the parts I think are relevant:
#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;
}