I am writing a small c code to revert back on the same number from which a recent message has come.I used
Serial.println("AT+CNMI=2,2,0,0"); and store its content in a string and then parse that string using strtok function.
now when number is stored in b, i need to concatenate it with At command.I am using strcat function to concatenate both string i.e.
AT+CMGS and number.So i stored AT+CMGS in another string and used strcat .
Am i heading in right direction or if any one has better idea to revert back on the OA of message.
There isn't a number stored in b. b is a pointer that points to a portion of a string. You should be making a copy of that string, using strdup() or strcat(), so that the data is preserved.
You should also have read the sticky about posting code. I seriously doubt that your code looks like that mess.
Well when i printed "b" on lcd using lcd.write(b);, it get printed successfully, my only doubt in that is there were certain characters coming in between the number, are those number due to the fact that i didn't make any copy of b, instead i printed it directly over LCD?
To help us understand your problem, it would be a good idea if you told us exactly what string you're starting with and what string you want to end up with. All we know so far is that it's whatever response you got when you sent "AT+CNMI=2,2,0,0" to something - presumably a GSM modem.
Not sure if it's ok for you to ignore that in general Serial.read() will return a -1 ???
( Unless a complete character has arrived from time to time... )
And I'd be very careful about strdup() ( or rather "suspicious" ). AFAIK, it takes dynamic memory ...
Better have that memory allocated statically ( if required ) and use strcpy.
It were hard lessons for me learning the word "should" actually means something that I'd retranslate as "absolutely must" as a non native English speaker.
Now I learn that "can" has the same meaning. A strange language
IMHO, there's usually no reason to use dynamic memory like malloc() on a controller with 2k RAM.