I've tried thousand options to parse the set of strings I store inside the buffer, but can't find a good way to store them string by string in the *args[] array of strings. What I want to do afterwards is to run execvp inside the Child process.
Thanks!!
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#define MAX_LINE 80
int main(){
char *args[MAX_LINE/2 + 1];
int should_run = 1;
int background = 1;
char buffer[1024];
while (should_run){
printf("jaime$ ");
int i = 0;
fflush(stdout);
while (fgets(buffer, 1024, stdin)){
sscanf(buffer, "%s", args[i]);
i++;
}
pid_t pid;
pid = fork();
if (pid < 1){
fprintf(stderr, "fork() failed");
..........
forksystem call, you're not checking for the correct return code.