1つ以上のスペースで区切られた複数の単語を含む文字列を分割し、スペースを含まない各単語を文字列の配列のインデックスに配置する関数を取得しようとしています。
私はしばらくそれをグーグルしてきました、私はstrtokが必要なようですが、私は少し無知です、誰かがいくつかの光を当ててくれませんか?
/* strtok example */
#include <stdio.h>
#include <string.h>
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;
}