Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct node {
- char *val;
- struct node * next;
- } node_t;
- /**
- * Returns true if word is in dictionary else false.
- */
- bool check(const char *word)
- {
- return false;
- }
- /**
- * Loads dictionary into memory. Returns true if successful else false.
- */
- bool load(const char *dictionary)
- {
- FILE *file = fopen(dictionary, "r");
- char * buffer = 0;
- long length;
- if (file)
- {
- fseek (file, 0, SEEK_END);
- length = ftell (file);
- fseek (file, 0, SEEK_SET);
- buffer = malloc (length);
- if (buffer)
- {
- fread (buffer, 1, length, file);
- }
- fclose (file);
- }
- char *token = NULL;
- char *delim = "\n";
- int i = 0;
- node_t * head = NULL;
- head = malloc(sizeof(node_t));
- if (head == NULL) {
- return 1;
- }
- token = strtok(buffer, delim);
- head->val = token;
- head->next = NULL;
- while (token != NULL){
- // printf("%d The token is: %s\n", i, token);
- head->next = malloc(sizeof(node_t));
- head->next->val = token;
- head->next->next = NULL;
- //printf("%d The token is: %s\n", i, &head->next->val);
- token = strtok(NULL, delim );
- i++;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement