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.

49 lines
1010B

  1. #include <stdlib.h> /* malloc */
  2. #include <errno.h> /* perror */
  3. #include <stdio.h> /* printf */
  4. #include <unistd.h> /* write */
  5. /* this define must precede uthash.h */
  6. #define HASH_EMIT_KEYS 1
  7. #include "uthash.h"
  8. #define BUFLEN 30
  9. typedef struct name_rec {
  10. char boy_name[BUFLEN];
  11. UT_hash_handle hh;
  12. } name_rec;
  13. int main(int argc,char *argv[])
  14. {
  15. name_rec *name, *names=NULL;
  16. char linebuf[BUFLEN];
  17. FILE *file;
  18. int i=0;
  19. if (argc != 2) {
  20. fprintf(stderr,"usage: %s file\n", argv[0]);
  21. exit(-1);
  22. }
  23. if ( (file = fopen( argv[1], "r" )) == NULL ) {
  24. perror("can't open: ");
  25. exit(-1);
  26. }
  27. while (fgets(linebuf,BUFLEN,file) != NULL) {
  28. name = (name_rec*)malloc(sizeof(name_rec));
  29. if (name == NULL) {
  30. exit(-1);
  31. }
  32. strcpy(name->boy_name, linebuf);
  33. HASH_ADD_STR(names,boy_name,name);
  34. i++;
  35. }
  36. fprintf(stderr,"%d keys emitted.\n", i);
  37. fclose(file);
  38. return 0;
  39. }