I am trying to fill an array (char*).
When I am filling the array, I make a print to display elements and it is OK.
But, after that, when I try to use the array away (in the main()
function), always it is filling with the last element.
typedef struct Device {
char *adr_mac;
char *rssi;
} Device;
Device * devices[6];
int array_length = 6;
void *changeRssi( void *tab)
{
int h = 0;
srand(time(NULL));
int rssi = 0;
char ch[2] = "";
while(1){
sleep(10);
printf("\n\n $$$ Changing RSSI of devices ...\n\n");
for (h = 0; h < array_length; h++)
{
rssi = generate_rssi(10,99);
sprintf(ch, "%d", rssi);
devices[h] -> rssi = ch;
printf("new rssi = %s\n\n", devices[h] -> rssi);
}
}
}