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[])
- {
- char *animal = "buffalo";
- char *name = "tommy";
- char *hi = "hello";
- char *greet = "stinkybutt";
- char *fish = "shrimp";
- char *a = "a";
- char *t = "t";
- char *s = "sir";
- char *test = "codex";
- char *alph = "abcdefghijklmnopqrstuvwxyz";
- char *ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- char *breed = "poodle";
- int val = 0;
- int namval = hash(name);
- int aval = hash(animal);
- int hasha = hash(a);
- int hasht = hash("t");
- int hasho = hash("o");
- int hashm = hash("m");
- int hashy = hash("y");
- node *dog = malloc(sizeof(node));
- node *contn = malloc(sizeof(node));
- node *anot = malloc(sizeof(node));
- for (int i = 0; breed[i] != '\0'; i++)
- {
- dog->word[i] = breed[i];
- }
- printf("dog->word prints: %s\n",dog->word);
- dog->next = contn;
- //printf("dog->next prints: %s\n",dog->next);
- for (int i = 0; fish[i] != '\0'; i++)
- {
- contn->word[i] = fish[i];
- }
- printf("contn->word prints: %s\n",contn->word);
- contn->next = anot;
- printf("contn->next->word prints: %s\n",contn->next->word);
- //printf("contn->next prints: %s",contn->next);
- for (int i = 0; greet[i] != '\0'; i++)
- {
- anot->word[i] = greet[i];
- }
- anot->next = dog;
- printf("contn->next->word prints: %s\n",contn->next->word);
- printf("anot->word prints: %s\n",anot->word);
- anot->next = dog;
- printf("dog->next->word prints: %s\n",dog->next->word);
- printf("anot->next->word prints: %s\n",anot->next->word);
- printf("animal[] = \n");
- for (int i = 0; animal[i] != '\0'; i++)
- {
- printf("animal[%i] = %c",i,animal[i]);
- printf("\n");
- }
- printf("dog prints: ");
- for (int i = 0; dog->word[i] != '\0'; i++)
- {
- printf("%c",dog->word[i]);
- }
- printf("\n");
- printf("anot prints: ");
- for (int i = 0; anot->word[i] != '\0'; i++)
- {
- printf("%c",anot->word[i]);
- }
- printf("\n");
- //node *table[N] = malloc(N*sizeof(node));
- node *table[N];
- //table[0]->word[0] = 'c';
- //table[2]->next = table[0];
- //->word[0];
- // print table[0]
- for (int i = 0; alph[i] != '\0'; i++)
- {
- table[0]->word[i] = alph[i];
- printf("table[0]->word[%i] = %c\n",i,table[0]->word[i]);
- }
- node *cursor = malloc(sizeof(node));
- //cursor = dog;
- for (cursor = dog; cursor->next != dog; cursor->next = cursor->word->next)
- {
- //int i = 0;
- printf("cursor->word prints %s\n", cursor->word);
- //i++;
- }
- free(contn);
- free(dog);
- free(anot);
- }
Advertisement
Add Comment
Please, Sign In to add comment