Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   pls help me (http://www.go4expert.com/forums/pls-help-me-t10093/)

Shilpa1 17Apr2008 14:40

pls help me
 
<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 18Apr2008 09:04

Re: pls help me
 
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.


All times are GMT +5.5. The time now is 22:12.