修改用户输入以在EXEC呼叫中使用

发布于 2025-01-27 01:29:28 字数 583 浏览 1 评论 0原文

我正在尝试修改用户输入字符串以在将来函数中调用execVP。在我的代码中,我具有一个函数,该函数可以使用户输入具有:如果用户输入:命令ab c。它输出char ** output = {“命令”,“ a”,“ b”,“ c”,null}用户输入的长度未知。 我的问题是我要修改变量char **输出以删除用户输入的命令,以便我获得char ** output = {“ a”,“ b”,“ c”,null} 我目前对此的尝试是在下面的代码中:

char** exec_arg(char** output, int numTokens){
143     char* argExec[numTokens];
147     for(int k = 0; k < (numTokens-1); k++){
148         argExec[k] = output[k+1];
149         printf("%s", argExec[k]);
150     }
152     return argExec;
155 }

但是,我发现当我运行时,我将得到输出:{“ a”,“ b”,“ c”}

I am trying to modify a user input string to call execvp in a future function. In my code I have a function which tokenises the user input such that if the user entered in: command a b c. It outputs char** output = { "command", "a", "b", "c", NULL } The length of the user input is unknown.
My issue is that I want to modify the variable char** output to remove the user entered command, such that I get char** output = {"a", "b", "c", NULL }
My current attempt at this is in the code below:

char** exec_arg(char** output, int numTokens){
143     char* argExec[numTokens];
147     for(int k = 0; k < (numTokens-1); k++){
148         argExec[k] = output[k+1];
149         printf("%s", argExec[k]);
150     }
152     return argExec;
155 }

However I am finding that when I run this I am getting the output: {"a", "b", "c"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文