3
Imagine you ask "when the capacity reaches the limit you should warn the user" I have an integer vector with 15 positions, and the user will enter values inside, the goal is to warn when to reach the end, as?
#include <stdio.h>
#include <stdlib.h>
#define MAX 15
int lerVectorDeInteiros(int *);
void mostrarVetor(int *);
void inicializarVetor(int *);
int main()
{
int vetor[MAX];
int quantidadeElementos = 0;
inicializarVetor(vetor);
quantidadeElementos =lerVectorDeInteiros(vetor);
printf("A quantidade de elementos que foram inseridos no vetor sao %d\n", quantidadeElementos);
mostrarVetor(vetor);
return 0;
}
void inicializarVetor(int vetor[MAX]){
int i;
for(i=0; i<MAX; i++){
vetor[i] = 0;
}
}
int lerVectorDeInteiros(int vetor[MAX]){
int i;
int temp = 0;
int contador = 0;
for(i=0; i<MAX; i++){
printf("Insire o valor da posicao %d do vetor: ", i+1);
scanf("%d", &temp);
if(temp > 99 && temp < 501){
vetor[i] = temp;
contador++;
}
}
return contador;
}
void mostrarVetor(int vetor[MAX]){
int i;
for(i=0; i<MAX; i++){
printf("O valor da posicao %d e: %d\n", i+1, vetor[i]);
}
}
"when the capacity reaches the limit you should warn the user" - If you are reading the amount corresponding to the size then you will never read more than the amount. So warning you when it’s over doesn’t make sense, unless you put a
printf
after thefor
reading to indicate that you have read everything. For me it is not very clear what you want to do.– Isac