I'm writing a C program to implement a shell that supports a few commands... one of them being "exit"
I made a table of commands that are supported and I wanted to use strcmp to match it to the command in the table. As of write now I cannot get the program match exit when typed.
Thanks for any help
here is the code:
Code:#include <stdio.h> #include <string.h> main() { char *delimeter= " "; char *tkn; char s[30]; char *cmd[]={"dir", "md", "sort", "cd", "type", "del", "exit","|",">"}; int i,f_des[2]; while(1) { printf(">"); fgets(s,30,stdin); tkn = strtok(s, delimeter); while(tkn != NULL) { if( strcmp(cmd[6],tkn) == 0){/*check if exit*/ exit(1); } if( strcmp(cmd[7],tkn) == 0){/*Check for piping*/ } if( strcmp(cmd[8],tkn) == 0){/*Check for > */ } } } }



LinkBack URL
About LinkBacks


