1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| int main(){
char * c = malloc(30);
char *pointeur = NULL;
char * c2 = malloc(30);
int i = 0;
while(1){
printf("$");
fgets(c,30,stdin);
/* ---PARSING--- */
strcpy(c2,c);
int i = 0;
pointeur = strtok(c," ");
while(pointeur != NULL){
pointeur = strtok(NULL," ");
i++;
}
char **mots = malloc(i+1);
pointeur = strtok(c2," ");
int k = 1;
mots[0] = pointeur;
while(pointeur != NULL){
pointeur = strtok(NULL," ");
mots[k] = pointeur;
k++;
}
/* ------------------- */
mots[i] = NULL;
int pid = fork();
//printf(" %d ",pid);
if(pid == 0){
execvp(mots[0],mots);
}
else{
wait();
}
}
return 0;
} |