⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uthash.c

📁 在LINUX下实现对哈希表的操作
💻 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 + -