Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <dirent.h>
- #include <sys/types.h>
- char command[50];
- char *command1;
- char cwd[1000];
- char *nameDirectory[40];
- int errno;
- int i=0;
- char historyTab[100][100];
- void history(char *tab){
- for(int j = 0; j <= i; j++) {
- printf("%s\n", historyTab + j);
- }
- }
- int main() {
- for(;;){
- getcwd(cwd,sizeof(cwd));
- printf("\x1b[32m[%s] \n$ \x1b[0m",cwd);
- fgets(command, sizeof(command), stdin);
- if(command[strlen(command) - 1] == '\n') command[strlen(command) - 1] = 0;
- strcpy(historyTab[i], command); i++;
- command1 = strtok(command," ");
- if(strcmp(command1,"history")==0){
- command1=strtok(NULL, " ");
- history(historyTab);
- }
- else{
- printf("Niemożliwe jest poprawne zinterpretowanie polecenia\n");
- printf("Wartosc bledu: %d\n", errno);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement