joseleeph

Untitled

Oct 22nd, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. //#define LENGTH 26;
  6.  
  7. typedef struct node
  8. {
  9. char word[26];
  10. struct node *next;
  11. }
  12. node;
  13. const unsigned int N = 26;
  14. //node *table[26];
  15.  
  16.  
  17. unsigned int hash(const char *word)// to hash a-z 0-26, maybe use ascii value and subtract?
  18. {
  19. int val = 0;
  20. //int cval;
  21. for (int i = 0; word[i] != '\0'; i++)
  22. {
  23. //val += word[i];
  24.  
  25. if (isalpha(word[i]))
  26. {
  27. if (isupper(word[i]))
  28. {
  29. val += word[i] - 65;
  30. }
  31. if (islower(word[i]))
  32. {
  33. val += word[i] - 97;
  34. }
  35. if (word[i] == 13)
  36. {
  37. continue;
  38. }
  39. }
  40. else
  41. continue;
  42.  
  43. }
  44. return val%26;
  45. }
  46. int main(int argc, char *argv[])
  47. {
  48. char *animal = "buffalo";
  49. char *name = "tommy";
  50. char *hi = "hello";
  51. char *greet = "stinkybutt";
  52. char *fish = "shrimp";
  53. char *a = "a";
  54. char *t = "t";
  55. char *s = "sir";
  56. char *test = "codex";
  57. char *alph = "abcdefghijklmnopqrstuvwxyz";
  58. char *ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  59. char *breed = "poodle";
  60. int val = 0;
  61. int namval = hash(name);
  62. int aval = hash(animal);
  63. int hasha = hash(a);
  64. int hasht = hash("t");
  65. int hasho = hash("o");
  66. int hashm = hash("m");
  67. int hashy = hash("y");
  68.  
  69. node *dog = malloc(sizeof(node));
  70. node *contn = malloc(sizeof(node));
  71. node *anot = malloc(sizeof(node));
  72.  
  73. for (int i = 0; breed[i] != '\0'; i++)
  74. {
  75. dog->word[i] = breed[i];
  76. }
  77. printf("dog->word prints: %s\n",dog->word);
  78. dog->next = contn;
  79.  
  80. //printf("dog->next prints: %s\n",dog->next);
  81.  
  82. for (int i = 0; fish[i] != '\0'; i++)
  83. {
  84. contn->word[i] = fish[i];
  85. }
  86. printf("contn->word prints: %s\n",contn->word);
  87. contn->next = anot;
  88. printf("contn->next->word prints: %s\n",contn->next->word);
  89. //printf("contn->next prints: %s",contn->next);
  90.  
  91. for (int i = 0; greet[i] != '\0'; i++)
  92. {
  93. anot->word[i] = greet[i];
  94. }
  95. anot->next = dog;
  96. printf("contn->next->word prints: %s\n",contn->next->word);
  97.  
  98. printf("anot->word prints: %s\n",anot->word);
  99. anot->next = dog;
  100.  
  101. printf("dog->next->word prints: %s\n",dog->next->word);
  102. printf("anot->next->word prints: %s\n",anot->next->word);
  103.  
  104. printf("animal[] = \n");
  105. for (int i = 0; animal[i] != '\0'; i++)
  106. {
  107. printf("animal[%i] = %c",i,animal[i]);
  108. printf("\n");
  109. }
  110.  
  111. printf("dog prints: ");
  112. for (int i = 0; dog->word[i] != '\0'; i++)
  113. {
  114. printf("%c",dog->word[i]);
  115. }
  116. printf("\n");
  117.  
  118. printf("anot prints: ");
  119. for (int i = 0; anot->word[i] != '\0'; i++)
  120. {
  121. printf("%c",anot->word[i]);
  122. }
  123. printf("\n");
  124.  
  125.  
  126. //node *table[N] = malloc(N*sizeof(node));
  127.  
  128. node *table[N];
  129.  
  130. //table[0]->word[0] = 'c';
  131.  
  132.  
  133. //table[2]->next = table[0];
  134. //->word[0];
  135.  
  136.  
  137.  
  138. // print table[0]
  139. for (int i = 0; alph[i] != '\0'; i++)
  140. {
  141. table[0]->word[i] = alph[i];
  142. printf("table[0]->word[%i] = %c\n",i,table[0]->word[i]);
  143. }
  144.  
  145. node *cursor = malloc(sizeof(node));
  146. //cursor = dog;
  147.  
  148. for (cursor = dog; cursor->next != dog; cursor->next = cursor->word->next)
  149. {
  150. //int i = 0;
  151. printf("cursor->word prints %s\n", cursor->word);
  152. //i++;
  153. }
  154.  
  155.  
  156.  
  157.  
  158. free(contn);
  159. free(dog);
  160. free(anot);
  161.  
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment