Problems with making a simple UNIX shell

Posted by Kodemax on Stack Overflow See other posts from Stack Overflow or by Kodemax
Published on 2010-04-01T08:55:22Z Indexed on 2010/04/01 9:03 UTC
Read the original article Hit count: 254

Filed under:
|

Hai, I am trying to create a simple shell in UNIX. I read a lot and found that everybody uses the strtok a lot. But i want to do without any special functions. So i wrote the code but i cant seem to get it to work. Can anybody point out what i am doing wrong here?

void process(char**);  
int arg_count;  
char **splitcommand(char* input)  
{  
    char temp[81][81] ,*cmdptr[40];  
    int k,done=0,no=0,arg_count=0;  
    for(int i=0 ; input[i] != '\0' ; i++)  
    {  
        k=0;  
        while(1)  
        {  
            if(input[i] == ' ')  
            {  
                arg_count++;  
                break;  
            }  
            if(input[i] == '\0')  
            {  
                arg_count++;  
                done = 1;  
                break;  
            }  
            temp[arg_count][k++] = input[i++];  
        }  
        temp[arg_count][k++] = '\0';  
        if(done == 1)  
        {  
            break;  
        }  

    }  
    for(int i=0 ; i<arg_count ; i++)  
    {  
        cmdptr[i] = temp[i];  
        cout<<endl;  
    }  

    cout<<endl;  

}  
void process(char* cmd[])  
{  
    int pid = fork();  
        if(pid < 0)  
        {  
        cout << "Fork Failed" << endl;  
        exit(-1);  
    }  
    else if( pid == 0)  
    {  
        cout<<endl<<"in pid";  
        execvp(cmd[0], cmd);  
        }  
        else  
        {  
          wait(NULL);  
          cout << "Job's Done" << endl;  
        }  
}  
int main()  
{  
    cout<<"Welcome to shell !!!!!!!!!!!"<<endl;  
    char input[81];  
    cin.getline(input,81);  
    splitcommand(input);  


}  

© Stack Overflow or respective owner

Related posts about c++

Related posts about shell