how can i store serial port available test to a two dimensional array. strings are separated with Z and end of text with # pls help if anyone alrdy a solution
i am posting my program here
String readstr;
String finalstr;
char *messages[][20] = { "" };
int i, k = 0, lp;
char chArray[] = "hai";
String str(chArray);
void setup() {
Serial.begin(9600);
Serial.println("System ready........"); // so I can keep track of what is loaded
}
void loop()
{
int flag = 0;
while (Serial.available() > 0)
{
char c = Serial.read(); //gets one byte from serial buffer
if (c == '#')
{
finalstr = readstr;
readstr = "";
flag = 1;
} // I am getting data here on #
else // and is available with finalstr
{
readstr += c; //makes the string readstr
}
}
if (flag == 1) // once data is available and terminated with #
{
int j = 0, l = 0;
flag = 0;
//Serial.print(finalstr.length());
for (i = 0; i < finalstr.length(); i++) //want to split in to strings
{
//Serial.println(finalstr.length());
// Serial.println(i);
if ((finalstr[i] != 'Z')) // if any char is Z, then split
{
// Serial.println(finalstr[3]);
messages[j][l] = finalstr[i]; // rearanging in to String messages
chArray[j] = finalstr[i];
messages[j][l] = '\0';
Serial.println(messages[j][i]); // here it is not working
l++;
// Serial.println(j);
}
else
{
l = 0;
j++;
String str(chArray);
// strncpy(messages[k],chArray,str.length()); // this is not working need help
// Serial.println(messages[0]);
//delay(2000);
Serial.println(k);
k++;
//Serial.println(str);
}
}
for (i = 0; i < j; i++)
{
Serial.println(messages[i]); // I am getting here garbage value
}
k = 0;
j = 0;
l = 0;
}
}