Basically, I should insert a number that represents the number of integers to insert. Then insert the integers into each other, separated by space, in the same input.
Example:
5
1 2 3 4 5
I tried to perform the following repetition, without much hope of knowing that there was something strange:
i=0;
scanf("%i", &numeros);
long int *vetor = malloc(numeros*sizeof(long int));
while(numeros > 0)
{
scanf("%i", &vetor[i]);
i++;
numeros--;
}
If we insert the example above, the vector does not receive the first integer, and the latter receives garbage. Something like: [2, 3, 4, 5, -13343256]
How could I read these integers from the same input?