33 lines
620 B
C
33 lines
620 B
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
struct t_ListElement {
|
|
char *val;
|
|
struct t_ListElement *next;
|
|
};
|
|
|
|
typedef struct t_ListElement item;
|
|
|
|
int searchList(item *head, char *name) {
|
|
item *curr = head;
|
|
int pos = 0;
|
|
while (curr) {
|
|
if (!strcmp(curr->val, name)) {
|
|
return pos;
|
|
}
|
|
++pos;
|
|
curr = curr->next;
|
|
}
|
|
if (!curr) {
|
|
return -1;
|
|
}
|
|
return pos;
|
|
}
|
|
|
|
item *newListItem(char *name) {
|
|
item *e = (item *)malloc(sizeof(item));
|
|
e->val = calloc(strlen(name)+1, sizeof(char));
|
|
e->next = NULL;
|
|
strcpy(e->val, name);
|
|
return e;
|
|
} |