Guest User

Untitled

a guest
Jun 30th, 2016
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1.  
  2. struct llist
  3. {
  4.     char name[128];
  5.     uint32_t value;
  6.     struct llist *next;
  7. };
  8.  
  9. typedef struct llist llist_t;
  10.  
  11. void list_insert(llist_t **list, const char *name, uint32_t value)
  12. {
  13.     llist_t *item = malloc(sizeof(struct llist));
  14.     strcpy(item->name, name);
  15.     item->value = value;
  16.     item->next = *list;
  17.     *list = item;
  18. }
  19.  
  20. uint32_t list_find(llist_t **list, const char *name)
  21. {
  22.     for(llist_t *it = *list; it != NULL; it = it->next)
  23.     {
  24.         if(strcmp(it->name, name) == 0) {
  25.             return it->value;
  26.         }
  27.     }
  28.     return -1;
  29. }
  30.  
  31. void list_free(llist_t **list)
  32. {
  33.     while((*list) != NULL)
  34.     {
  35.         llist_t *next = (*list)->next;
  36.         free(*list);
  37.         (*list) = next;
  38.     }
  39. }
Add Comment
Please, Sign In to add comment