I need to make a code where the user populates a vector as many times as he wants, but the code stops rolling. If I only register 3 values, like (1) (2) (3) it works normally, but at some moments (there is no default) the program stops running. I could not find my fault.
Follow the code:
#include<stdio.h>
main(){
int *vetor, i, d, contador=0;
char c;
vetor=NULL;
do{
if(contador==0)
vetor=malloc(1*sizeof(int));
else
realloc(vetor,1*sizeof(int));
printf("Digite um valor para salvar no vetor: ");
scanf("%d", &d);
*(vetor+contador)=d;
contador++;
printf("Deseja cadastrar mais um numero? ");
scanf(" %c", &c);
system("pause");
} while(c == 's' || c == 'S');
system("cls");
for(i=0; i<contador; i++)
printf(" (%d) ", vetor[i]);
}