I need to do an exercise in which the code allocates memory as needed, but I need to relocate an array of structs, but I ended up locking in that part.
My Struct is:
typedef struct{
char nome[100];
char endereco[100];
int numero;
char telefone[11];
char sexo;
char cpf[11];
data nascimento;
double saldo;
}cliente;
I created the pointer that will get the address of my struct inside the function main()
.
cliente *cliente;
Allocated memory to only 1 position of my struct
cliente = malloc(sizeof(cliente));
During the execution of my code, I reallocate the memory to receive another "client", using
cliente = (struct cliente*) realloc(cliente, tam*sizeof(cliente));
But when I use the function to show the registered clients, all appear with memory garbage in the variables, except the last one, what am I doing wrong?