开发者

How can I change the array to be filled from user input?

This code works for what i am trying to do, but I need the string to be put in by the user. How can I change the array t开发者_运维知识库o be user based?

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


In C/C++ you can use scanf to take such input from a user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜