0

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

char*token;

while(1){

    //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 

Edited by shaneetra.graham

3
Contributors
2
Replies
13
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

split.h

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.