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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.