diff options
Diffstat (limited to 'tests/test31.c')
-rw-r--r-- | tests/test31.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test31.c b/tests/test31.c new file mode 100644 index 000000000..58bfb7356 --- /dev/null +++ b/tests/test31.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "utlist.h" + +#define BUFLEN 20 + +typedef struct el { + char bname[BUFLEN]; + struct el *next, *prev; +} el; + +static int namecmp(void *_a, void *_b) +{ + el *a = (el*)_a; + el *b = (el*)_b; + return strcmp(a->bname,b->bname); +} + +int main() +{ + el *name, *tmp; + el *head = NULL; + + char linebuf[BUFLEN]; + FILE *file; + + file = fopen( "test11.dat", "r" ); + if (file == NULL) { + perror("can't open: "); + exit(-1); + } + + while (fgets(linebuf,BUFLEN,file) != NULL) { + name = (el*)malloc(sizeof(el)); + if (name == NULL) { + exit(-1); + } + strcpy(name->bname, linebuf); + CDL_PREPEND(head, name); + } + CDL_SORT(head, namecmp); + CDL_FOREACH(head,tmp) { + printf("%s", tmp->bname); + } + + fclose(file); + + return 0; +} |