Dealing with input in C

你离开我真会死。 提交于 2019-12-13 17:38:04

问题


A brief question really, looking for, wondering about, and asking for any tips for what the best way is to handle this type of input:

 word word
 word word word word
 word word word
 word word

whereby the number of words on each line is totally random, and each separate word can be added to some data structure, like a linked list or tree for example.

Fgets each line and parse? Getchar()? Any clues?


回答1:


Reading one line at a time with fgets seems like the best option here. Then just use strtok or something similar to split by empty space and iterate over the result.



来源:https://stackoverflow.com/questions/8467405/dealing-with-input-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!