苗火 Nicholas
[c]uthash
2016-10-14 萧


An example about uthash



#include "uthash.h"
#include <stdlib.h> /* malloc */
#include <stdio.h> /* printf */

typedef struct _user_t {
int id;
char name[25];
UT_hash_handle hh;
} USER_T,*PUSER_T;

void main()
{
int i;
PUSER_T user, users=NULL;

/* create elements */
for(i=0; i<10; i++) {
user = (PUSER_T)malloc(sizeof(USER_T));
if (user == NULL) {
exit(-1);
}
user->id = i;
sprintf(user->name,"Hello, nicholas. %d", i);
HASH_ADD_INT(users,id,user);
}

for(user=users; user; user=(PUSER_T)(user->hh.next)) {
printf("user %d, name %s\n", user->id, user->name);
}
return 0;
}

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容