Hello, I need help making my shell in c. The shell needs to ignore spaces, this means that you can put the spaces you want an the command needs to work, I already resolved that problem, the next problem is that if you put ; two commands need to be recognized for example "ls ; ps", I need help in that problem
P.D : I need to use execvp and fork
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
int pid;
int i,j,k;
char s[200];
char command[20][10];
char **order;
char *orderptr[20];
int m;
int bol = 0;
fflush(stdin);
printf(">");
gets(s);
/* while a command is input, parse it and split into words of
different size, each is then stored in the command array */
while (strlen(s)!=0) {
for (k=0; k<20; k++) command[k][0]=(char) NULL;
for (k=0; k<20; k++) orderptr[k]=NULL;
i=j=0;
//Spaces at the end
m = strlen(s)-1;
while ( m >= 0){
if(s[m] == ' '){
s[m] = (char) NULL;
m--;
}else{
break;
}
}
bol = 0;
for (k=0; k<strlen(s); k++) {
if (s[k]!=' ') {
command[i][j]=s[k];
j++;
bol = 1;
}
else {
if (bol == 1){
command[i][j]=(char) NULL;
orderptr[i]=&command[i][0];
i++; j=0;
bol = 0;
}
}
}
/* Indicate there is no other argument */
command[i][j]= (char) NULL;
/* Update pointers */
orderptr[i]=&command[i][0];
order = &orderptr[0];;
ptr = strtok(*order,";");
while(ptr != NULL){
printf("%sn",ptr);
ptr = strtok(NULL, " ");
}
if ((pid = fork())>0) wait(NULL);
else {
execvp(*order,order);
printf("There was an error executing that command\n");
}
fflush(stdin);
printf(">");
gets(s);
}
}
Thank you