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.

55 lines
1.2KB

  1. #include "uthash.h"
  2. #include <stdlib.h> /* malloc */
  3. #include <errno.h> /* perror */
  4. #include <stdio.h> /* printf */
  5. #define BUFLEN 20
  6. #if 0
  7. #undef uthash_expand_fyi
  8. #define uthash_expand_fyi(tbl) printf("expanding to %d buckets\n", tbl->num_buckets)
  9. #endif
  10. typedef struct name_rec {
  11. char boy_name[BUFLEN];
  12. UT_hash_handle hh;
  13. } name_rec;
  14. int main()
  15. {
  16. name_rec *name, *names=NULL;
  17. char linebuf[BUFLEN];
  18. FILE *file;
  19. int i=0,j=0;
  20. file = fopen( "test14.dat", "r" );
  21. if (file == NULL ) {
  22. perror("can't open: ");
  23. exit(-1);
  24. }
  25. while (fgets(linebuf,BUFLEN,file) != NULL) {
  26. i++;
  27. name = (name_rec*)malloc(sizeof(name_rec));
  28. if (name == NULL) {
  29. exit(-1);
  30. }
  31. strcpy(name->boy_name, linebuf);
  32. HASH_ADD_STR(names,boy_name,name);
  33. }
  34. fseek(file,0L,SEEK_SET);
  35. while (fgets(linebuf,BUFLEN,file) != NULL) {
  36. HASH_FIND_STR(names,linebuf,name);
  37. if (!name) {
  38. printf("failed to find: %s", linebuf);
  39. } else {
  40. j++;
  41. }
  42. }
  43. fclose(file);
  44. printf("lookup on %d of %d names succeeded\n", j, i);
  45. return 0;
  46. }