LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Release the pointer obtained from strtok

Hi,
 
Having the following code:
 
char *Token = NULL;
 
Token = strtok("string","s");
 
How can I release the Token after I will no longer use the variable?
 
0 Kudos
Message 1 of 6
(3,517 Views)
Hi,

what do you mean by 'release'?

If you want want to free allocated space I'm not sure it's necessary in this case.

Usually, when you allocate space to a pointer with malloc() or other functions, use free().



0 Kudos
Message 2 of 6
(3,512 Views)
Hi Danut81.

There is no storage associated with your variable Token; it is a char * which the function strtok() sets to point to the next token found in your string, so there is nothing to free.

Regards,
Colin.

0 Kudos
Message 3 of 6
(3,497 Views)
Don't "free" the Token. It's (just) a pointer into the "string" you want to process by strtok(). Similar to strchr() and others.
-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 4 of 6
(3,496 Views)
Bingo!
0 Kudos
Message 5 of 6
(3,494 Views)
Thanks for the information.
Topic closed
0 Kudos
Message 6 of 6
(3,488 Views)