0
Basically, I must enter a number that represents the amount of integers to be entered. Then insert the integers themselves, separated by space, into the same input.
Example:
5
1 2 3 4 5
I tried to perform the following repetition, without much hope knowing that there was anything 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 up there, the vector does not receive the first integer, and the last receives garbage. Something like: [2, 3, 4, 5, -13343256]
How could I read these integers from the same input?
Could post the code of how you did the test?
– Cahe
I discovered the error by debugging.
– michelvmelo
Your code seems to work well, see Osvaldo’s response. I also tested it here.
– Cahe