last-modified: 2019-04-28 (日) 18:36:58 (1837d)[変更箇所]
char* strtok(char* s1, const char* s2)
文字列s1をs2で分割して返す。使い方はいろんなサイトであるが、以下のような感じ。s1は最終的に破棄されてしまうのでいったんコピーする。
string s[100]; char* ctemp; strcpy(c_copy,c_org); ctemp = strtok(c_copy,";"); n=0; while(ctemp !=NULL){ s[n]=(string)ctemp; //remove left/right spaces n++; ctemp = strtok(NULL,";"); }
他の書き方もあるけれど、c_orgが";"のみで構成されている場合も考慮するとこれが一番良い書き方では?