?? uthash.c
字號:
#include <stdio.h>
#include <string.h>
#include"uthash.h"
typedef struct Information Information;
struct Information
{
char name[64]; //個人姓名
char sex[16]; //性別
int height; //身高
};
typedef struct MM_REPORTDATA_HASH MM_REPORTDATA_HASH;
struct MM_REPORTDATA_HASH
{
char name[64]; //個人姓名
char sex[16]; //性別
int height; //身高
UT_hash_handle hh;
};
MM_REPORTDATA_HASH*gpHead = NULL;
int main(int argc, char **argv)
{
//Information hh;
Information *pData;
pData = (Information*)malloc(sizeof(Information));
//獲得數據
//cout<<"please input information data"<<endl;
//cin>>pData->name;
//cin>>pData->sex;
//cin>>pData->height;
puts("please input information data");
gets(pData->name);
gets(pData->sex);
scanf("%d",&pData->height);
//向哈希表中加入數據
MM_REPORTDATA_HASH *pNewHash;
pNewHash=(MM_REPORTDATA_HASH*)malloc(sizeof(MM_REPORTDATA_HASH));
strcpy(pNewHash->name,pData->name);
strcpy(pNewHash->sex,pData->sex);
pNewHash->height = pData->height;
//cout<<pNewHash->name<<endl;
//puts(pNewHash->name);
HASH_ADD_STR(gpHead,name,pNewHash);
//查找數據,然后輸出
MM_REPORTDATA_HASH *pTemp=NULL;
if(gpHead && gpHead->hh.tbl->num_items>0)
HASH_FIND_STR(gpHead,pData->name,pTemp);
printf("find data and puts\n");
puts(pTemp->name);
puts(pData->sex);
printf("%d\n",pData->height);
//刪除哈希表的數據
HASH_DEL(gpHead,pTemp);
free(pTemp);
//查看是否哈希表的數據被刪除
HASH_FIND_STR(gpHead,pData->name,pTemp);
if(!pTemp)
{
printf("data has been dele!!!\n");
printf("complete my work :)\n");
}
else
{
printf("please dele data!!");
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -