Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "utlist.h"
  5. #define BUFLEN 20
  6. typedef struct el {
  7. char bname[BUFLEN];
  8. struct el *next, *prev;
  9. } el;
  10. static int namecmp(void *_a, void *_b)
  11. {
  12. el *a = (el*)_a;
  13. el *b = (el*)_b;
  14. return strcmp(a->bname,b->bname);
  15. }
  16. int main()
  17. {
  18. el *name, *tmp;
  19. el *head = NULL;
  20. char linebuf[BUFLEN];
  21. FILE *file;
  22. file = fopen( "test11.dat", "r" );
  23. if (file == NULL) {
  24. perror("can't open: ");
  25. exit(-1);
  26. }
  27. while (fgets(linebuf,BUFLEN,file) != NULL) {
  28. name = (el*)malloc(sizeof(el));
  29. if (name == NULL) {
  30. exit(-1);
  31. }
  32. strcpy(name->bname, linebuf);
  33. DL_APPEND(head, name);
  34. }
  35. DL_SORT(head, namecmp);
  36. DL_FOREACH(head,tmp) {
  37. printf("%s", tmp->bname);
  38. }
  39. /* now delete the list head */
  40. printf("deleting head %shead->prev: %s", head->bname, head->prev->bname);
  41. DL_DELETE(head,head);
  42. DL_FOREACH(head,tmp) {
  43. printf("%s", tmp->bname);
  44. }
  45. fclose(file);
  46. return 0;
  47. }