Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <string.h>
  6.  
  7. #include <unistd.h>
  8.  
  9. #include <dirent.h>
  10.  
  11. #include <sys/types.h>
  12.  
  13.  
  14.  
  15.  char command[50];
  16.  
  17.     char *command1;
  18.     char cwd[1000];
  19.  
  20.     char *nameDirectory[40];
  21.  
  22.     int errno;
  23.  
  24.     int i=0;
  25.  
  26.     char historyTab[100][100];
  27.  
  28.  
  29.  
  30.  
  31. void history(char *tab){
  32.     for(int j = 0; j <= i; j++) {
  33.         printf("%s\n", historyTab + j);
  34.     }  
  35.  
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42. int main() {
  43.  
  44.  
  45.  
  46. for(;;){
  47.  
  48.         getcwd(cwd,sizeof(cwd));
  49.  
  50.         printf("\x1b[32m[%s] \n$ \x1b[0m",cwd);
  51.  
  52.         fgets(command, sizeof(command), stdin);
  53.  
  54.         if(command[strlen(command) - 1] == '\n') command[strlen(command) - 1] = 0;
  55.         strcpy(historyTab[i], command); i++;
  56.  
  57.         command1 = strtok(command," ");
  58.  
  59.  
  60.  
  61.     if(strcmp(command1,"history")==0){
  62.  
  63.             command1=strtok(NULL, " ");
  64.  
  65.             history(historyTab);
  66.  
  67.        }
  68.  
  69.     else{
  70.  
  71.             printf("Niemożliwe jest poprawne zinterpretowanie polecenia\n");
  72.  
  73.             printf("Wartosc bledu: %d\n", errno);
  74.  
  75.         }
  76.  
  77.     }
  78.  
  79.     return 0;
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement