+ 1

Strings in C

How can I scan multiple strings separated with spaces and put each part in an array?

28th Dec 2018, 2:55 PM
Matin Zamani
Matin Zamani - avatar
1 Réponse
+ 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," "); }
28th Dec 2018, 3:58 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar