+ 1
Strings in C
How can I scan multiple strings separated with spaces and put each part in an array?
1 ответ
+ 5
You can use strtok to read a string delimited by some set of tokens. Then you can store those pieces in a new array of C-strings.
For more information on usage and all, visit: www.cplusplus.com/reference/cstring/strtok
The code will look like: (str is the original)
char res[10][100]; int n=0;
char* pch = strtok(str," ");
while(pch!=NULL)
{
strcpy(res[i],pch);
pch = strtok(NULL," ");
}