修改用户输入以在EXEC呼叫中使用
我正在尝试修改用户输入字符串以在将来函数中调用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论