1
I’m doing a job for college, and it’s basically about hash table. At work, I have to do a Hash table of a n strings, for example. Instead of making an array of characters (in this case, an array of strings), I would like to implement a chained list, because then at the end I could add more strings in the list and in the hash table.
However, I’m having trouble implementing a string chained list, because I don’t know how "cell", for example, can store an array (in this case, the string, character array).
The help I ask here then, is to help me turn the following code I made (which generates random words of random size) into a chained list. Basically insert the variable word[i] on the chained list.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <locale.h>
int main() {
srand(time(NULL));
setlocale(LC_ALL, "");
int strQty = 100;
int strLimit = 11;
int ascMin = 97;
int ascMax = 122;
char words[strQty][strLimit];
// Gerando strings aleatorias
int i, j;
int size, letter;
for (i=0; i<strQty; i++) {
// Tamanho da palavra words[i] -- de 1 a 10.
size = rand()%(10)+1;
for (j=0; j<size; j++) {
letter = rand()%(ascMax-ascMin)+ascMin;
words[i][j] = (char)letter;
}
// Indica o fim da string
words[i][size] = '\0';
}
// Lendo strings geradas
for (i=0; i<strQty; i++) {
printf("Posição [%03d], tamanho [%02d], Palavra [%s]: ", i, strlen(words[i]), words[i]);
for (j=0; j<strlen(words[i]); j++) {
printf("%c", words[i][j]);
}
printf("\n");
}
}
In addition, I await the answers and thank you for your help!