2
我想写用C假的外壳,所以我需要能够接受命令,然后接受命令的x个参数。当我真正运行这个命令时,我只使用execvp(),所以我只需要将参数解析到一个数组中。但我不确定如何在不知道确切数字的情况下如何做到这一点。我正在想像一些伪代码,如:
while (current char in command line != '\n')
if current char is a space, increment a counter
parse characters in command line until first space and save into a command variable
for number of spaces
while next char in command line != a space
parse chars into a string in an array of all of the arguments
有关如何将其放入代码的任何建议?
这似乎是一样的[ 解析串入的argv/argc个 ](http://stackoverflow.com/questions/ 1706551 /)。特别是,请参阅[GLib答案](http://stackoverflow.com/questions/1706551/parse-string-into-argv-argc/1706610#1706610)。 – 2010-10-03 02:00:30