joseleeph

Untitled

Oct 20th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 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.  
  49.  
  50. 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
  51. node *contn = malloc(sizeof(node));
  52. node *anot = malloc(sizeof(node));
  53.  
  54.  
  55. node *table[N];
  56.  
  57.  
  58. table[0]->word[0] = 'c';
  59. table[0]->word[1] = 'h';
  60. table[0]->word[2] = 'a';
  61. table[0]->word[3] = 'n';
  62. table[0]->word[4] = 'g';
  63. table[0]->word[5] = 'e';
  64. table[0]->word[6] = '\0';
  65.  
  66. table[0]->next = table[1];
  67.  
  68. table[1]->word[0] = 'f';
  69. table[1]->word[1] = 'o';
  70. table[1]->word[2] = 'r';
  71. table[1]->word[3] = 'g';
  72. table[1]->word[4] = 'e';
  73. table[1]->word[5] = '\0';
  74.  
  75. table[1]->next = table[2];
  76.  
  77. table[2]->word[0] = 's';
  78. table[2]->word[1] = 'e';
  79. table[2]->word[2] = 'b';
  80. table[2]->word[3] = 'u';
  81. table[2]->word[4] = 'm';
  82. table[2]->word[5] = '\0';
  83.  
  84. table[2]->next = table[0];
  85. //->word[0];
  86.  
  87.  
  88. // print table[0]
  89. for (int i = 0; table[0]->word[i] != '\0'; i++)
  90. {
  91. //node *modnod = malloc(sizeof(node));
  92. // initialize the table and allocate memory for the nodes to be midified
  93. table[0] = malloc(sizeof(node));
  94. // allocate
  95. printf("table[0]->word[%i] = %c\n",i,table[0]->word[i]);
  96. free(table[0]);
  97. }
  98.  
  99.  
  100.  
  101. free(contn);
  102. free(dog);
  103. free(anot);
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment