You need to provide your entire sketch if you want people to help. Your sr buffer is only 1 char in length but you are trying to put 2 chars into it? Buffer overrun....
ok thanks.This is another problem I am facing actually!!
But still I am getting "&" as output instead of "GT" &"CF"
The "GT" should have no connection with the issues you all have pointed out as above.
Thanks for figuring out the another prob!
Try putting in some extra serial.PrintLn so you can see what happens on each step:
strcpy (tempChars,buf);
char * strtokIndx;
strtokIndx = strtok (tempChars,",");
serial.PrintLn (strtokIndx);
strcpy (messageFromPC,strtokIndx);
serial.PrintLn (messageFromPC);
strtokIndx = strtok (NULL,",");
strcpy (sID,strtokIndx); >> this should be getting the alphabet "GT"
serial.PrintLn (strtokIndx);
serial.printLn (sID);
strtokIndx = strtok (NULL,",");
serial.PrintLn (strtokIndx);
strcpy (dID,strtokIndx); >> this should be getting the alpahbet "CF"
serial.PrintLn (dID);
You should then see why you don't have the data you expect. If you need help with the output, put up the whole sequence of PrintLn output starting with buf (that you already print out).
stephanie9:
I have tried to print out. It showed like this:
P >> this one no prob
& >> this should be GT
? >> the question mark is reversed in the serial monitor and it should be CF
The reason for putting the lines in as I showed in the code is so that you can see at each step what has happened, rather than just look at the end and see that isn't what was expected.
Also for those of us not familiar with exactly what you are sending the contents on buf would help us.
Makes no sense to declare a pointer to a 'const char' and then try to modify the data at that pointer. You should have gotten at least a compiler warning for that.
Now GT and CF are shown in the receiver side!!
But the matching part is still a problem.
byte y = strcmp(diD, "CF");[color=#222222][/color]
if(y ==0) //null-characters terminated strings have matched[color=#222222][/color]
{[color=#222222][/color]
//do something[color=#222222][/color]
}
so for this one, If they are matching, should I put inside if or else?
not so familiar with this strcmp
Updated:
I put inside if and it works!!
now is another prob:
byte y = strcmp(dID, "CF");
if(y ==0) //null-characters terminated strings have matched
{
char data [25];
sprintf(data,"P,%s,%c,Yes,route: ",src_ID,sID,src_ID);
for the route, I am planning to append on it every time the message has been sent.
So it is going to be longer for more time of transmission.
How should I do for that?
byte y = strcmp(dID, "CF");
if(y ==0) //null-characters terminated strings have matched
{
char data [25];
sprintf(data,"P,%s,%s,Yes,route: %s ",src_ID,sID,src_ID);
What I mean is that, I wanted to add more data like "CF" for example append on the route part.
So that if the message has been transferred twice, it should show two ID there, by using append method
Sorry I don't quite follow what the problem is, what append method are you referring to?.
This might be caused by me being tired it being nearly midnight here and I was up early.