I am making a code where you have a vector (with 15 positions) with predetermined values (10 any values and 5 times the value 0), and where the user will enter a new value to go to the end of the list ( substituting 0).
It seems to me that everything is right here, but the vector does not "get" the typed value. It performs everything right, with no error, just does not replace 0 with the new value.
The code (as part of a larger code, a switch
with 7 options, I'm going to put this part with error not to get too big and with unnecessary parts):
case 1 : printf("Qual valor voce quer inserir no final? ");
scanf ("%d",&x1);
n1 = 15;//posições do vetor
num = 1;
x2 = 1;
printf("lista atual:\n"); //Exibe como está a lista
while (num <= n1)
{
printf ("%d ", vet[num]);
num++;
}
while (num <= n1) //roda o laço e caso encontre uma posição do vetor igual a zero, subtitui
{
if (vet[num] == 0)
{
vet[num] = x1;
}
num++;
}
printf ("\n\nNova lista:\n");
while (num <= n1)
{
printf ("%d", vet[num]);
num++;
}