strtok ( ) help



I'm using strtok( ) to capture lines of input. After I call
"splitCommand", I call strtok( ) again to get the next line. Strtok( )
returns NULL (but there is more in the file...). That didn't happen
before 'splitCommands' entered the picture. The problem is in
splitCommands( ) somehow modifying the pointer, but I HAVE to call that
function. Is there a way to make a copy of it or something ?

/* HERE IS MY CODE */

char * lineOfScript;
const char * delim = "\n";

lineOfScript = strstr(scriptFileBuffer,":preprocess:"); //find starting
place in script
lineOfScript = strtok(lineOfScript,delim); //skip a line
lineOfScript = strtok(NULL,delim); //get next line... now I have a
command
splitCommand(lineOfScript); //this is probably where my pointer gets
messed up...
lineOfScript = strtok(NULL,delim); //get next line, but strtok returns
NULL

//Split up command into seperate words.
//Store words in global array
int splitCommand(char * command){
const char * delimeters = " ";
int i = 0;
g_UserCommands[0] = strtok(command, " ");
while(g_UserCommands[i] != NULL && i < 5){
//printf("%s", g_UserCommands[i]);//for debugging...
i+=1;
g_UserCommands[i] = strtok(NULL, " ");
}
i=0;
return 1;
}

.



Relevant Pages

  • Re: strtok ( ) help
    ... I call strtok() again to get the next line. ... > before 'splitCommands' entered the picture. ... it makes a copy of whatever lineOfScript pointed ... its internal buffer as set by whatever lineOfScript originally pointed to. ...
    (comp.lang.c)
  • Re: crazy problem with strtok puttings ptrs in **argv
    ... i suspect it's in the ptr to ptr ... > want to make a dozen strtok calls. ... > single command to be split up in tokens and put nicely in my **argv. ... it will "tokenize" the string using ...
    (comp.lang.c)
  • Re: Two-Dimensional Char Array
    ... > I'm having problems where I need to parse a command line, ... > each token from strtok() into an array. ...
    (comp.lang.c)
  • Re: Parsing Data
    ... I am trying to parse some data that looks like: ... Is the problem that you do not know about strtok? ... I didn't know what command to go about seperating the data ...
    (comp.soft-sys.matlab)