// apologise for the mysterious words.. but some of the but p,q have good reasons to be
// their in the original application.
Code:
/* The following segment looks for the string starting with ‘add person’ .
IF FOUND, it would check for the number of persons in the party.
p, q refers to the character count, starting from the 11th count it reads the characters and puts them in a character string str1[] unless a blank space is found . */
static int t;
char *chid;
char ch_id[4];
char *ch_ids[4];
if(strstr(buffer,"add person"))
{
for(p=11,q=0;buffer[p]!=' ';p++,q++) // No. of persons
{
str1[q]=buffer[p];
}
str1[q]='\0';
num=atoi(str1);
printf("Num::%d",num);
nos=num;
t=11+strlen(str1);
/* nos refers to number of numbers . Say for three persons it would create room for an array of 3 strings. */
while(nos>0)
// this is the number of numbers reducing with each char string
{
x=0;
for( i = t+1, p = 0; buffer[i] ! = ' ' && p<4 ; i++, p++)
{
ch_id[p]=buffer[i];
t=i;
}
ch_id[p]='\0';
// printf(" %d ). %x\n" ,x,ch_id);
strcpy(chid,ch_id);
ch_ids[x]=chid;
x+=1;
nos-=1;
free(chid);
}
//The rest part of the application goes here.
}
The desired output should be
Command : “ add friends 3 2005 2007 2009”
Output[1] : 2005
Output[1] : 2007
Output[1] : 2009