Corrupt variables using char array
code:
--------------------------------------------------------
serial monitor data:
floncur:
-38.69
flatcur:
-12.89
clatcur:
-12.888442
cloncur:
-38 o 9
4 = < |d < ro m
<gps>
no match...
------------------------------------------------
the variable cloncur should be:
-38.685349
but comes out garbage:
-38 o 9
4 = < |d < ro m
any ideas of what's going on?
code: [select]
void loop()
{
convertlongitude(longitude);
convertlatitude(latitude);
serial.println("floncur: ");
serial.println(floncur);
serial.println("flatcur: ");
serial.println(flatcur);
cloncur = dtostrf(floncur,1,6,bufferlon);
cloncur +='\0';
clatcur = dtostrf(flatcur,1,6,bufferlat);
clatcur +='\0';
serial.println("clatcur: ");
serial.println(clatcur);
serial.println("cloncur: ");
serial.println(cloncur);
char* sms_text= "<gps>";
char* ccommand;
int istart=0;
int iend=0;
(int i=0; i<10;i++)
{
if(sms_text[i]=='<') istart=i;
else if (sms_text[i]=='>') iend=i;
}
(int i=istart+1; i<iend;i++)
{
ccommand[i]=sms_text[i];
}
serial.println(istart);
serial.println(iend);
serial.println(ccommand);
serial.println(sms_text);
if (ccommand=="ver")
{
serial.println("text=ver");
}
else if (ccommand=="gps")
{
serial.println("text=gps");
}
else if (ccommand=="pos")
{
serial.println("text=pos");
}
else serial.println("no match...");
delay(2000);
}
--------------------------------------------------------
serial monitor data:
floncur:
-38.69
flatcur:
-12.89
clatcur:
-12.888442
cloncur:
-38 o 9
4 = < |d < ro m
<gps>
no match...
------------------------------------------------
the variable cloncur should be:
-38.685349
but comes out garbage:
-38 o 9
4 = < |d < ro m
any ideas of what's going on?
Arduino Forum > Using Arduino > Programming Questions > Corrupt variables using char array
arduino
Comments
Post a Comment