I'm having issues with some code that I'm writing for a class homework, which is to write a simple shell for linux. I was wandering if anyone knew a way to convert a char* to a char** in a better way that what I am using.
Currently I'm accepting in a char*, making a copy of it so that I don't modify the passed char*, and using strtok to try to split the contained strings into an array of char*. I'm kind of fuzzy on the last portion, is a datatype of char* str[] the equivalent of a char**?
The main reason I'm doing this is that I need to feed that char* into execvpe and it requires a value of char**. I've included my code below.
Thank you,
Andy
char**
createArgv(char *passedString){
int counter;
counter = 0;
char *tempString, *cpPassedString;
cpPassedString = malloc(sizeof(INPUT_BUFFER));
*cpPassedString = *passedString;
tempString = strtok(cpPassedString," \n");
char *tempArray[INPUT_BUFFER];
while(tempString != NULL){
tempArray[counter] = tempString;
tempString = strtok(NULL, " \n");
++counter;
}
return tempArray;
}
Edit: Why in the world is my text different colors?