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.

51 lines
876B

  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. LL_PREPEND(head, name);
  34. }
  35. LL_SORT(head, namecmp);
  36. LL_FOREACH(head,tmp) {
  37. printf("%s", tmp->bname);
  38. }
  39. fclose(file);
  40. return 0;
  41. }