'Modify user input to use in exec call
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"}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
