开发者

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

开发者 https://www.devze.com 2023-03-09 03:44 出处:网络
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?

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

精彩评论

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