pnode_t create_link(void) { pnode_t phead = NULL; FILE *fp; int ch; long pos; char word[WORD_LEN]; fp = fopen(DICT_FILENAME, "r+"); if (fp == NULL) { IERROR("open file '%s' error", DICT_FILENAME); exit(1); } while ((ch = getc(fp)) != EOF) { if (ch == '#') { pos = ftell(fp); fgets(word, WORD_LEN - 1, fp); phead = insert_to_link(phead, word, pos); } } fclose(fp); return phead; }
V_NODE *create_link(void) { V_NODE *head = NULL; FILE *fp = fopen("dict.txt", "r+"); if(fp == NULL) { perror("open"); exit(1); } char c; char w[WORD_LEN]; long pos = 0; while((c = getc(fp)) != EOF) { if(c == '#') { pos = ftell(fp); fgets(w, WORD_LEN-1, fp); head = insert_to_link(head, w, pos); } } fclose(fp); return head; }