1
My program stores 10 numbers in a vector and Zera the numbers that are less than 0. I am receiving these two error messages:
- Passing argument 1 of 'Zeranegativos' makes Pointer from integer without a cast [-Wint-Conversion]
- Expected 'int *' but argument is of type 'int'
I’ve tried to put the "and commercial" (&) in the function call and the asterisk (*) in the function parameter to signal a pointer, but it didn’t work either. The code below:
#include <stdio.h>
void ZeraNegativos(int entrada[]) {
for (int i = 0; i < 9; i++) {
if (entrada[i] < 0) {
entrada[i] = 0; //zera todo número menor do que zero
}
}
for (int i = 0; i < 9; i++) {
printf("%i", entrada[i]);
}
}
int main() {
int numeros[9];
for (int i = 0; i < 9; i++) {
scanf("%i", &numeros[i]); //armazena os números no array
}
ZeraNegativos(numeros[9]);
return 0;
}
In error message: display the line where the error occurs ?
– alexjosesilva
Line 19 and line 3.
– Lucas Souza
Stores 9 numbers, not 10. The fact of starting to count at zero, not "sum 1" in amount when you declare
int numeros[9]
: you reserve space for 9 numbers. Imagine a rule with 9 centimeters: in the mark '9' you are at the end of it, it does not fit anything else. But you can put something between the '0' and '1cm' marks of the ruler: that means count.– jsbueno