struct args
{
    char command[64];
    char args[2][64];
};

int argscount = 0;
struct args* arguments;
int buffersize = 64;
char *ptoken = NULL;
char input[buffersize];
char *pstr = NULL;



int a = read(0,input,buffersize);
pstr = input;
arguments = malloc(sizeof(struct args));
if(a>0){
    ptoken = strtok(&pstr," ");
    strcpy(arguments->command,ptoken);
    printf("TOKEN:%s\n", ptoken);
    while( ptoken != NULL ) {
        if(argscount > 1){break;}
        ptoken = strtok(NULL, ' ');
        strcpy(arguments->args[argscount],ptoken);
        argscount++;
    }
}

最佳答案

问题很可能是

ptoken = strtok(&pstr," ");

strtok的第一个参数应该是
char *

你把它当作
char **

关于c - Strtok()段错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19601495/

10-10 02:48