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.
精彩评论