showtree prints error

This commit is contained in:
Jakub Adamski 2019-01-19 18:59:56 +01:00
parent 0f2b0f2919
commit 4f18787256
2 changed files with 9 additions and 6 deletions

Binary file not shown.

View File

@ -35,19 +35,21 @@ void rmChar(char *str, char garbage) { /*przesledzic jak to dziala!!!!! w opis
*dst = '\0'; *dst = '\0';
} }
void cd (char **argv){ int cd (char **argv){
if(argv[1] == NULL){ if(argv[1] == NULL){
printf("Add arguments\n"); printf("Add arguments\n");
return; return -1;
} }
else if(argv[2] != NULL){ else if(argv[2] != NULL){
printf("Too many arguments\n"); printf("Too many arguments\n");
return; return -1;
} }
else{ else{
if (chdir(argv[1]) != 0) if (chdir(argv[1]) != 0){
perror("chdir error"); perror("chdir error");
return; return -1;
}
return 0;
} }
} }
@ -117,7 +119,8 @@ void tree (char **argv, char * directory){
printf("Showtree prints catalog and file structure\ntakes no arguments \nor exacly 1 argument for desired directory\n"); printf("Showtree prints catalog and file structure\ntakes no arguments \nor exacly 1 argument for desired directory\n");
exit(0); exit(0);
} }
cd(argv); if(cd(argv) == -1)
exit(0);
getcwd(ndr, sizeof(ndr)); getcwd(ndr, sizeof(ndr));
} }
else else