I need to implement a list that is simply chained that does not have an indication of next, that is, it should work as a vector, accessing nearby positions in memory. I am using the realloc () command to try to implement, however I am getting error when I am going to access any of the items in the list.
Struct that I'm using:
typedef struct Lista lista;
struct Lista {
char nome[81];
char telefone[15];
char celular[15];
char endereco[101];
};
Function to insert in the list:
void insererealloc(lista **l, int t)
{
*l = (lista*) realloc(*l, (t)*sizeof(lista));
setbuf(stdin, NULL);
printf("Digite o nome");
gets((*l)->nome);
setbuf(stdin, NULL);
printf("Digite o telefone");
gets((*l)->telefone);
setbuf(stdin, NULL);
printf("Digite o celular");
gets((*l)->celular);
setbuf(stdin, NULL);
printf("Digite o endereco");
gets((*l)->endereco);
setbuf(stdin, NULL);
}
All right until then! The problem occurs when I try to "start" the elements of the list, I am accessing them as a pointer, for example: list [i] -> name, where i is any position. What is the correct way to access these members?
NOTE: I know that gets () is not at all reliable, though I'm just testing and I'm a little lazy to use fgets () or something better.