I'm making my own command prompt (school project) and I'm trying to keep track of the last 10 commands the user uses. So I have an array:
char* history[10];
From my understanding this means I have an array of pointers, which point to strings. My problem with this is that I have another variable, input that is the users input. But whenever the user inputs something new, then the value of input changes, meaning all of the strings in my array change to the user's new input.
I'm wondering how I can get around this?
I tried changing my array to the following:
char *history[10][MAX] //Where MAX = 256
Where I could instead use strcpy instead but I was unable to figure out how to input an array of arrays into a method, and then use strcpy to copy the string into the array of arrays.
Here is my current method:
char* updateHistory(char *history[], char command[], int histIndex) {
history[histIndex] = command;
return *history;
}
Any help on another solution or how to get my solution working?