strtok - String Function - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

strtok - String Function

tokoGtokoG Posts: 209Member
Hi

Another question on String Function, strtok.

For strtok, here is the explanation, http://www.cplusplus.com/ref/cstring/strtok.html
and my question follows in [b][blue]blue[/b][/blue]

Summerize what they say... is this simply to separate [b]delimiter[/b] from other deliminater...? Then, is using [b]while[/b] the only way to see its result...?

This is the trial code introduced on the site above;
[code]
/* strtok example */
#include
#include

int main ()
{
char str[] ="This is a sample string,just testing.";
char * pch;
printf ("Splitting string "%s" in tokens:
",str);
pch = strtok (str," ");
while (pch != NULL)
{
printf ("%s
",pch);
pch = strtok (NULL, " ,.");
}
return 0;
}
[/code]

[b]Output[/b]
Splitting string "This is a sample string,just testing." in tokens:
This
is
a
sample
string
just
testing

Comments

  • tsagldtsagld Posts: 621Member
    : Hi
    :
    : Another question on String Function, strtok.
    :
    : For strtok, here is the explanation, http://www.cplusplus.com/ref/cstring/strtok.html
    : and my question follows in [b][blue]blue[/b][/blue]
    :
    : Summerize what they say... is this simply to separate [b]delimiter[/b] from other deliminater...? Then, is using [b]while[/b] the only way to see its result...?
    :
    : This is the trial code introduced on the site above;
    : [code]
    : /* strtok example */
    : #include
    : #include
    :
    : int main ()
    : {
    : char str[] ="This is a sample string,just testing.";
    : char * pch;
    : printf ("Splitting string "%s" in tokens:
    ",str);
    : pch = strtok (str," ");
    : while (pch != NULL)
    : {
    : printf ("%s
    ",pch);
    : pch = strtok (NULL, " ,.");
    : }
    : return 0;
    : }
    : [/code]
    :
    : [b]Output[/b]
    : Splitting string "This is a sample string,just testing." in tokens:
    : This
    : is
    : a
    : sample
    : string
    : just
    : testing
    :


    Correct.


    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

  • tokoGtokoG Posts: 209Member
    : : Hi
    : :
    : : Another question on String Function, strtok.
    : :
    : : For strtok, here is the explanation, http://www.cplusplus.com/ref/cstring/strtok.html
    : : and my question follows in [b][blue]blue[/b][/blue]
    : :
    : : Summerize what they say... is this simply to separate [b]delimiter[/b] from other deliminater...? Then, is using [b]while[/b] the only way to see its result...?
    : :
    : : This is the trial code introduced on the site above;
    : : [code]
    : : /* strtok example */
    : : #include
    : : #include
    : :
    : : int main ()
    : : {
    : : char str[] ="This is a sample string,just testing.";
    : : char * pch;
    : : printf ("Splitting string "%s" in tokens:
    ",str);
    : : pch = strtok (str," ");
    : : while (pch != NULL)
    : : {
    : : printf ("%s
    ",pch);
    : : pch = strtok (NULL, " ,.");
    : : }
    : : return 0;
    : : }
    : : [/code]
    : :
    : : [b]Output[/b]
    : : Splitting string "This is a sample string,just testing." in tokens:
    : : This
    : : is
    : : a
    : : sample
    : : string
    : : just
    : : testing
    : :
    :
    :
    : Correct.
    :
    :
    : Greets,
    : Eric Goldstein
    : www.gvh-maatwerk.nl
    :
    :

    [blue]
    OK, thanks for confirming my understanding. ;)
    [/blue]
Sign In or Register to comment.