Hi,
I wrote the following code that in each 0.5 seconds the string in an array of string is re-defined. The code works fine in the beginning, but after some time when I re-define the string position in the array of string (myStrings[k]=strdup(str);), the position of array of string is always equal to zero.
Could you can help me?
int led = 13;
long previousMillis = 0;
int ledState = LOW;
long interval = 1000;
char str[25];
int k=1;
int ll=1;
const int num=10;
char* myStrings[num];void setup() {
Serial.begin(9600);
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;}if (ledState == LOW){ledState = HIGH;
if (k==num+1){k=1;}
snprintf(str, sizeof(str), ", k value = %d", k);
Serial.print("ll value = ");Serial.print(ll);
myStrings[k]=strdup(str);
Serial.println(myStrings[k]);
ll=ll+1; k=k+1;}
else
{delay(500);ledState = LOW;}
}