Trying to implement a history function in C, I know my array size for the history is 100 and i have a max of 9 arguments. I just wanted a little help or advice on where to start! I also know that i need my history initialized before i start parsing my shell commands. What i have so far:
#define MAX_ARGS 9
#define HIS_SIZE 100
typedef struct
{
int argument; // userCom arguments
char *arg[MAX_ARGS + 1]; // userCom arguments array
char* history[HIS_SIZE];
char *input; // hold iniut file
char *output; // hold outiut file
};Command
printf("\n%s@myshell:%s>", username,cwd);
//gets string from userCom line
fgets(buffer, MAX_COMMAND_SIZE + 1, stdin);
buffer[strlen(buffer)-1] = 0 ;//set null
//SETUP HISTORY FUNCTION
//parses tokens and looks for delimiters
token[tok] = strtok(buffer,whitespace);
while(token[tok])
{
++tok;
if(tok == MAX_ARGS)
printf("Reached MAX userCom arguments");
break;
token[tok] = strtok(NULL, whitespace);
}