Reputation: 821
I am new to Berkeley DB and learning using online guide. Now i have the following code below:
DB *dbp;
DBT key, data;
int ret, t_ret;
int k = 1;
key.data = &(k);
key.size = sizeof(k);
memset(&key, 0, sizeof(key));
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
{
printf("db: %d: key stored.\n", (char*)key.data);
}
Now the printf statement, instead of returning value "1", is returning something else. Don't know where I am going wrong.
Upvotes: 1
Views: 109
Reputation: 11616
Since key.data is a void*, you need to dereference it to get the value. Try:
printf("db: %d: key stored.\n", *(int*)key.data);
Upvotes: 1