string concatenation for sending message to a originating address of a message

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.

char str[100];
 int x=0;
 for(x=0;x<100;x++)
 {
  str[x]=Serial.read();
 x++;
 }
 char *str1= strdup(str);
        char *a = strtok(str1,":");
        char *b =  strtok(NULL,",");
        lcd.clear();
        lcd.write(b);

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.

Am i heading in right direction

Sort of. Keep in mind that strtok() will change the address that the pointer points to, not the address of the pointer, so:

        char *a = strtok(str1,":");
        char *b =  strtok(NULL,",");

will have a and b pointing to the same thing.

now when number is stored in b

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?

 char *a = strtok(str1,":");
        char *b =  strtok(NULL,",");

with this a and b , both were not pointed to the same thing, rather a was pointing to CMT+ and b to OA(Originating address.)

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.

Well when i printed "b" on lcd using , it get printed successfully,

But, what does a point to after b gets assigned a value?

And I'd be very careful about strdup() ( or rather "suspicious" ). AFAIK, it takes dynamic memory

It does. But, that memory can be freed when no longer needed.

that memory can be freed when no longer needed

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 :wink:

IMHO, there's usually no reason to use dynamic memory like malloc() on a controller with 2k RAM.