strtok ( ) help
- From: "ern" <erniedude@xxxxxxxxx>
- Date: 20 Jan 2006 09:16:59 -0800
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;
}
.
- Follow-Ups:
- Re: strtok ( ) help
- From: Gregory Pietsch
- Re: strtok ( ) help
- From: pemo
- Re: strtok ( ) help
- From: Vladimir S. Oka
- Re: strtok ( ) help
- Prev by Date: Re: NULL returned by fopen - where is a list of what's causing the error?
- Next by Date: Re: Pointer arithmetic question
- Previous by thread: ask for help on algorithm to trace a network
- Next by thread: Re: strtok ( ) help
- Index(es):
Relevant Pages
|