I was having a little trouble with parsing my command upon input, I'm new to C so any help would be greatful! Here is what i have so far i'm trying to make a simple unix shell



    //prints users prompt 
    printf("\n%s@myshell:%s>", username,curDirect); 

    //gets string from command line
    fgets(buffer, MAX_COMMAND_SIZE + 1, stdin);

    //parses tokens 
    token = strtok(buffer,whitespace);
    while(token != NULL)
        if(strcmp(token, "<") == 0)
             parse to <
        else if(strcmp(token, ">" == 0)
         //parse to >
            else if(strcmp(token, "&",1 == 0)
        token = strtok(NULL,whitespace);

    }//token while loop 

    }//end while loop 

    return 0; 
}//End Main loop 

Recommended Answers

All 2 Replies

You might like to look at split.h ... that emulates the Python split function in C

A C string input, with the delimiters, returns a Clist of 'words' (dynamic C strings)... parsed out in accord with your choice of delimiters passed in.


There are a few errors in the code you posted, such as lines 17 and 23. Line 24 is inside the if statement that begins on line 23.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.