I'm doing a job for college, and it's basically about Hash table . At work, I have to do the hash table of a n strings, for example. Instead of doing an array of character arrays (in this case, an array of strings), I would like to implement a linked list, because so in the end I could add more strings in the list and in the hash table.
However, I'm having trouble implementing a threaded list of strings, as I do not know how the "cell", for example, can store a vector (in this case, the string, vector of characters).
The help I ask here then is to help me transform the following code I made (which generates random random-sized words) into a linked list. Basically, insert the variable word [i] in the linked 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] = '#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] = '%pre%';
}
// 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");
}
}
';
}
// 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");
}
}
More, I await the answers and thank you for the help!