Good morning all. I'm new and my English is not so good.
The problem I have is this. I need to create a vector containing integers in a particular order, for example: 3,4,3,4,3 and back to another function. The problem that arises is that apparently the return pointer is corrupted in some way. This is the code:
int * calculador_de_diagonales::funcion_superior_vector(int round_floor, int round_ceil, int valor_resto_dem_resto, int denominador){
int i=0,r=1;
int *vec_v = (int*)malloc(denominador);
// memset(vec, 1, denominador);
// int vec_v[denominador];
for(i=0;i<denominador;i++){
if(((i+1)%2 == 0)&&(r <= valor_resto_dem_resto)){
vec_v[i]=round_ceil;
r++;
}else{
vec_v[i]=round_floor;
}
}
for(i=0;i<denominador;i++){
Serial.print(vec_v[i]);/*Serial.print("(");Serial.print(i);Serial.print(")");*/Serial.print(",");
}
Serial.println("");
// int vec[10] = {0,1,2,3,4,5,6,7,8,9};
return vec_v;
}
before returning the code, see what contains the vector and all good, but to see him out of the function does not contain what I want, but pure garbage.
This is the vector that I want: 4,3,4,4,4,
This is the vector that appears. 2,2,2,2,2