Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i have a problem when i use hash_set #9

Open
lixiaocan opened this issue Aug 23, 2017 · 0 comments
Open

i have a problem when i use hash_set #9

lixiaocan opened this issue Aug 23, 2017 · 0 comments

Comments

@lixiaocan
Copy link

lixiaocan commented Aug 23, 2017

sorry,i'm a newbie,Who can tell me the problem of following code?
//code

int main(int args,char *argv[])
{
    hash_t *hash_tab = NULL;
    char k[32] = {0};
    char cont[8] = {0};
    int value = 0;
    hash_tab = hash_new();
    do {
        printf("input key\n");
        scanf("%s",k);
        printf("input value\n");
        scanf("%d",&value);
        if(!hash_has(hash_tab,k))
            hash_set(hash_tab,k,&value);
        printf("conitinue add key? [y|n]\n");
        scanf("%s",cont);
    }while(!strcasecmp("y",cont));
    hash_each(hash_tab, {
                printf("%s: %d\n", key, *(int *) val);
                });
    hash_free(hash_tab);
}

//exe:
./test
input key
li
input value
2
conitinue add key? [y|n]
y
input key
yan
input value
3
conitinue add key? [y|n]
n
yan: 3
yan: 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant