I'm trying to make an array, and the vast majority of the values are incorrect. The only values that are correct are the ones I am giving a non-zero value. any value I give a value of zero seems to pick its own value from thin air. If I don't assign a zero value, the values are still not zero. Any help would be much appreciated
for (int i = 0; i<PDOL_Counter; i++){
if (i == Location9F66){
PDOL_message[i] = 0xF0;
PDOL_message[i+1] = 0x20;
PDOL_message[i+2] = 0x50;
PDOL_message[i+3] = 0x00;
nextdata = i+Length9F66;
}
}
I assume the array PDOL_message is a local variable defined inside { }
local variables are not initialised - they take whatever values are in the memory allocated at the time
to ensure that the array is initialised do it explicitly, e.g. initialised elements to 0
{
int PDOL_message[100]={0};
.......
}
global variables defined outside functions are initialised to 0 when the program starts execution
currently, the entire code is about 400 lines. the array is defined in the line above the loop. it isn't used at any point before or after this loop at the moment.