i have a C code which preforms some linux commands i need use upper arrow key in order get previous input so far the commands works fine but i failed to use upper arrow key to get previous commands (upper arrow key each time i press will get previous command and so on) how to do it ?
while (!feof(stdin)) {
fputs (prompt, stdout);
fflush(stdout);
if (fgets(lbuf, BUF, stdin )) {
arg = args;
*arg++ = strtok(lbuf,"\n\t");
if (args[0]) {
if (!strcmp(args[0],"exit")) {
break;
}
else if(!strcmp(args[0],"ls")) { system("ls"); }
else if (!strcmp(args[0],"help")) { system("bash -c help"); }
else if (!strcmp(args[0],"dir")){ strcpy( command, "dir" ); system(command); }
else if (!strcmp(args[0],"whoami")){ char username[MAX_USERID_LENGTH]; cuserid(username); printf("%s\n", username); }
else if (!strcmp(args[0],"clear")){ system("@cls||clear"); }
else { printf("command not found \n"); }
}
}
}
return 0;
}