473,698 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about hash in search.h (glibc, unix)

Hello all!!

How I can return data from a hash:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <search.h>

void exists(char *k){
//add values into a hash
ENTRY e,*ep; int c=1;
e.key = k;
ep = hsearch(e, FIND);
printf("%9.9s -> %9.9s:%d \n", e.key,
ep ? ep->key : "NULL",
ep ? (int)(ep->data) : 0);
e.key=k;
e.data = (char *)c;
ep = hsearch(e, ENTER);
if (ep == NULL) {
fprintf(stderr, "entry failed\n");
exit(1);
}

}

void rec(){
//call exists()
char num[3];
int i,j;
for (i = 2; i <= 3; i++) {
for (j = 2; j <= 3; j++) {
sprintf(num,"%d %d",i,j);
exists(num);
}
}

}

int main() {
ENTRY e,*ep; char nums[3];
int ii=8;
int i,j;
hcreate(ii);
i=2;j=2;
rec();
// show data from hash
for (i = 2; i <= 3; i++) {
for (j = 2; j <= 3; j++) {
sprintf(nums,"% d %d",i,j);
e.key = nums;
ep = hsearch(e, FIND);
printf("[%9.9s -> %9.9s:%d ]\n", e.key,
ep ? ep->key : "NULL",
ep ? (int)(ep->data) : 0);
}
}
return 1;

}

$ gcc test.c;./a.out
2 2 -> NULL:0
2 3 -> NULL:0
3 2 -> NULL:0
3 3 -> NULL:0
[ 2 2 -> NULL:0 ]
[ 2 3 -> NULL:0 ]
[ 3 2 -> NULL:0 ]
[ 3 3 -> NULL:0 ]
$

Where I have made a mistake? If not a mistake, as it is necessary to
make to see it data?

thank you for help!

dmitriyk kuvshinov aka vilfred

p.s. sorry for crosspost into gnu.glibc.bug

Nov 15 '05 #1
3 1694
le******@mail.r u wrote:
Hello all!!

How I can return data from a hash:

To even compile your code, I had to change everything before the
definition of exists() to

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* Everything through 'end of non-standard additions' is non-standard
and may be very different on your implementation, both in form and
function */

typedef struct
{
char *key;
void *data;
} ENTRY; /* non-standard type added */

typedef enum
{ FIND, ENTER } ACTION; /* non-standard enum added */

ENTRY *hsearch(ENTRY, ACTION); /* prototype for non-standard function
added */

int hcreate(size_t) ; /* prototype for non-standard function
added */

/* end of non-standard additions */
But, of course, it still doesn't link. Please take your question to a
place where it is topical. Perhaps a linux group will do you.
Nov 15 '05 #2
thank you for answer!

i'm sorry for posting my message in windows specific gorup...

dmitriy

Nov 15 '05 #3
le******@mail.r u wrote:
thank you for answer!

i'm sorry for posting my message in windows specific gorup...


comp.lang.c is not a windows-specific group. Your code was
*nix-specific. But C is not tied to a platform. All platform-specific
questions are off-topic. We are much more often accused of being
anti-windows and pro-*nix than being windows-specific.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
481
by: Zhiqiang Ye | last post by:
Hi,dear all, I know there is a hash library in glibc, it's head file is search.h. One can use hash map based on this.But its hash is global , there could be only one hash structrue at one time. Is there good hash library to that I can use it as a local data structure? Thanks a lot! Zhiqiang Ye
7
2636
by: Zhiqiang Ye | last post by:
Hi,dear all, I know there is a hash library in glibc, it's head file is search.h. One can use hash map based on this.But its hash is global , there could be only one hash structrue at one time. Is there good hash library to that I can use it as a local data structure? Thanks a lot! Zhiqiang Ye
1
3273
by: Pieter Claassen | last post by:
Is there any reasonable standard hash table storage in C on Linux? AFAICT the one in glibc has a data struct where the key and value pairs both have to be null terminated pointers. In my case, that is fine for the key, but I need to store a complex struct as the value and short of doing dangerous things like printing the memory location of the value struct and then recasting it when I want to get to the struct (which I think is...
1
2099
by: Sergei Koveshnikov | last post by:
Hello, I am trying to use hash management (from <search.h>). I can add and search however I can't update entries in the hash table... In the manual I found following note: ============ man (3) HSEARCH SVID and POSIX 1003.1-2001 specify that action is significant only for unsuccessful searches, so that an ENTER should not do anything for a successful search. The libc and glibc implementations update the data
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.