【发布时间】:2013-10-26 00:35:38
【问题描述】:
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++;
}
}
【问题讨论】:
标签: c segmentation-fault strtok