开发者

Not printing proper value of "key.data" in Berkeley DB using C

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 = &开发者_如何学运维amp;(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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜