You can use strtok function in c string library.

/* 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;
}


Referenced from: http://www.cplusplus.com/reference/clibrary/cstring/strtok/


2011/4/18 Sakthi Priyan <[email protected]>

> *C++*
> *
> *
> *Please ignore my previous reply and try this one...*
> *
> *
> # include <iostream>
> # include <string>
> # include <vector>
> # include <sstream>
> using namespace std;
> int main()
> {
>     string line = "this is a string", temp;
>     istringstream liness( line );
>     vector<string> splittedstrings;
>     while (liness >> temp)
>     {
>        splittedstrings.push_back (temp);
>     }
>     for (int i=0; i < splittedstrings.size(); i++)
>     {
>         cout << splittedstrings[i] << endl;
>     }
> }
>
> On Mon, Apr 18, 2011 at 12:37 PM, Sakthi Priyan <
> [email protected]> wrote:
>
>> *C++:*
>>
>> string line = "this is a string", temp;
>>
>> istringstream liness( line );
>>
>> getline( liness, temp, ' ' );
>>
>> vector<string> splittedstrings;
>>
>> while (temp != "")
>> {
>>
>>    splittedstrings.push_back (temp);
>>
>>    getline( liness, temp, ' ' );
>>
>> }
>>
>>
>>
>> On Mon, Apr 18, 2011 at 12:22 PM, Vinay Julme <[email protected]>wrote:
>>
>>> Java:
>>> String []str = "this is a string".split(" ");
>>> for(int i = str.length-1; i >=0; i--)
>>> System.out.println( str[ i ] );
>>>
>>>
>>> 2011/4/18 João Víctor Rocon Maia <[email protected]>
>>>
>>>> Python:
>>>> tokens = raw_input().split(' ')
>>>> for i in tokens:
>>>>    print i
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "google-codejam" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/google-code?hl=en.
>>>>
>>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "google-codejam" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/google-code?hl=en.
>>>
>>
>>
>>
>> --
>> - Thanks and Regards,
>>
>> *Sakthipriyan*
>>
>
>
>
> --
> - Thanks and Regards,
>
> *Sakthipriyan*
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>



-- 
G.Ç.

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to