gpt4 book ai didi

C - 解析带有未知数量参数的命令行

转载 作者:太空宇宙 更新时间:2023-11-04 00:10:05 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Parse string into argv/argc

我正在尝试使用 C 编写一个伪造的 shell,因此我需要能够接受一个命令,然后是该命令的 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

关于如何将其放入代码中有什么建议吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com