Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的文字:(第一个单词):word2,word3,...
ab: 1a,2b,3c,4d c: 5e,6f,7g
ab: 1a,2b,3c,4d
c: 5e,6f,7g
我想将右侧分配到这样的数组中:
arr1[4] = {1a,2b,3c,4d} arr2[3] = {5e,6f,7g}
现在我像这样逐行迭代
while ( fgets ( line, sizeof line, file ) != NULL ){...}
你能建议一种拆分行的方法,这样我就可以在没有第一个单词和逗号的情况下分别取每个单词吗?
怎么样:
while (...) { if (!strtok(line, ": ,")) continue; while ((word = strtok(NULL, ": ,"))) /* ... */ }