c - Strtok not creating a token -
i trying parse char * array tokens , researching strtok. whenever run code, doesn't return temporary value , wondering doing wrong
int length; int = 0; int tokencounter = 0; int commandcounter = -1; char *temptoken; char tempinput[max_line]; length = read(stdin_fileno, tempinput, max_line); commandcounter = -1; if (length < 0) { perror ("there error reading command"); } else if (length == 0) { exit (0); } else { (i = 0; < length; ++i) { if (tempinput[i] == "\n" || tempinput[i] == ' ' || tempinput == "\t") { /* if (commandcounter != -1) { ptokens[tokencounter] = &tempinput[commandcounter]; ++tokencounter; } tempinput [i] = '\0'; commandcounter = -1; */ } else { temptoken = strtok (tempinput, " \n"); while (temptoken != null) { strcpy(ptokens[tokencounter], temptoken); temptoken = strtok (tempinput, " \n"); } ++tokencounter; } } } ptokens[tokencounter] = null;
temptoken = strtok (tempinput, " \n");
other first time null
pointer has passed strtok
, mean inside while
loop, null
has passed instead of string.
temptoken = strtok (null, " \n");
Comments
Post a Comment