0
In one part of my program I need to create a vector full of zeros the size of the user’s interval:
scanf("%ld %ld", &n1, &n2);
int *vetor;
vetor = malloc((n2 - n1 + 1) * sizeof(long int));
for (long int k = 0; k <= n2; k++)
{
vetor[k] = 0;
}
But when I type in a few ranges, like 10 1000000, the program gives Segmentation fault right away, what can be?
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero