pls help me

Shilpa1's Avatar, Join Date: Nov 2007
Go4Expert Member
<CODE>
/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}
</CODE>

In the above example output is
This
a
sample
string

Now I want to store "This" and "sample" into one String and 'a" and "string" into another string.How to do this?pls help me.
bashamsc's Avatar, Join Date: May 2007
Go4Expert Member
Quote:
Originally Posted by Shilpa1
<CODE>
/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}
</CODE>

In the above example output is
This
a
sample
string

Now I want to store "This" and "sample" into one String and 'a" and "string" into another string.How to do this?pls help me.
In while use array to store This , a , sample and string . And after loop use strcat() function to store This and sample in a string and same for other.