#include <stdio.h>
#include <string.h>
struct _Phone_Entry {
int64_t id;
const char *number;
};
typedef struct _Phone_Entry Phone_Entry;
static Phone_Entry _start_entries[] = {
{ 1, "+01 23 456-78910" },
{ 2, "+12 34 567-89101" },
{ 3, "+23 45 678-91012" },
{ 4, "+34 56 789-10123" },
{ -1, NULL }
};
static void
_phone_entry_free_cb(void *data)
{
free(data);
}
{
const int64_t *id = key;
const char *number = data;
printf("%lld: %s\n", (long long int)*id, number);
}
int
main(int argc, const char *argv[])
{
(void)argc;
(void)argv;
int i;
int64_t entry_id = 4;
char *phone = NULL;
void *data;
for (i = 0; _start_entries[i].id != -1; i++)
{
strdup(_start_entries[i].number));
}
if (phone)
{
printf("Printing entry.\n");
printf("Id: %lld\n", (long long int)entry_id);
printf("Number: %s\n\n", phone);
}
printf("Hash entry successfully deleted? %d\n\n", r);
int64_t id3 = 3;
strdup("+23 45 111-11111"));
free(phone);
int64_t id5 = 5;
strdup("+55 01 234-56789"));
if (!phone)
{
printf("No previous phone found for id5. ");
printf("Creating new entry.\n");
}
else
{
printf("Old phone for id5 was %s\n", phone);
free(phone);
}
printf("\n");
strdup("+55 02 222-22222"));
if (phone)
{
printf("Changing phone for id5 to +55 02 222-22222. ");
printf("Old phone was %s\n", phone);
free(phone);
}
else
{
printf("No previous phone found for id5. ");
printf("Creating new entry.\n");
}
printf("List of phones:\n");
printf("\n");
printf("List of phones:\n");
{
const int64_t *id = t->key;
const char *number = t->data;
printf("%lld: %s\n", (long long int)*id, number);
}
printf("\n");
printf("List of ids in the phone book:\n");
{
const int64_t *id = data;
printf("%lld\n", (long long int)*id);
}
printf("\n");
printf("List of numbers in the phone book:\n");
{
const char *number = data;
printf("%s\n", number);
}
printf("\n");
printf("There are %d items in the hash.\n\n",
int64_t id6 = 6;
printf("List of phones after change:\n");
printf("\n");
printf("There are %d items in the hash.\n\n",
}