Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- //#define LENGTH 26;
- typedef struct node
- {
- char word[26];
- struct node *next;
- }
- node;
- const unsigned int N = 26;
- //node *table[26];
- unsigned int hash(const char *word)// to hash a-z 0-26, maybe use ascii value and subtract?
- {
- int val = 0;
- //int cval;
- for (int i = 0; word[i] != '\0'; i++)
- {
- //val += word[i];
- if (isalpha(word[i]))
- {
- if (isupper(word[i]))
- {
- val += word[i] - 65;
- }
- if (islower(word[i]))
- {
- val += word[i] - 97;
- }
- if (word[i] == 13)
- {
- continue;
- }
- }
- else
- continue;
- }
- return val%26;
- }
- int main(int argc, char *argv[])
- {
- node *dog = malloc(sizeof(node)); // allocate a space of memory big enough for a node and sotre it in a pointer to a node called poodle
- node *contn = malloc(sizeof(node));
- node *anot = malloc(sizeof(node));
- node *table[N];
- table[0]->word[0] = 'c';
- table[0]->word[1] = 'h';
- table[0]->word[2] = 'a';
- table[0]->word[3] = 'n';
- table[0]->word[4] = 'g';
- table[0]->word[5] = 'e';
- table[0]->word[6] = '\0';
- table[0]->next = table[1];
- table[1]->word[0] = 'f';
- table[1]->word[1] = 'o';
- table[1]->word[2] = 'r';
- table[1]->word[3] = 'g';
- table[1]->word[4] = 'e';
- table[1]->word[5] = '\0';
- table[1]->next = table[2];
- table[2]->word[0] = 's';
- table[2]->word[1] = 'e';
- table[2]->word[2] = 'b';
- table[2]->word[3] = 'u';
- table[2]->word[4] = 'm';
- table[2]->word[5] = '\0';
- table[2]->next = table[0];
- //->word[0];
- // print table[0]
- for (int i = 0; table[0]->word[i] != '\0'; i++)
- {
- //node *modnod = malloc(sizeof(node));
- // initialize the table and allocate memory for the nodes to be midified
- table[0] = malloc(sizeof(node));
- // allocate
- printf("table[0]->word[%i] = %c\n",i,table[0]->word[i]);
- free(table[0]);
- }
- free(contn);
- free(dog);
- free(anot);
- }
Advertisement
Add Comment
Please, Sign In to add comment