Should I free strtok() results?

Chris Calabrese cjc at ulysses.att.com
Tue Apr 10 22:58:20 AEST 1990


In article <6501 at rouge.usl.edu>, pcb at gator.cacs.usl.edu (Peter C. Bahrs) writes:
> The string functions that return pointers to memory, should their
> results be freed?

These functions don't use the malloc library routines unless they
explicitly say so in the man page.

Strtok, in particular, uses the original string you pass it as its
scratch buffer.  That's why the man page says that it modifies the
original string.

Most of the other string library routines do something similar.
For instance, strcat cats the second string onto the end of the first
string - no internal buffer used here either.
-- 
Name:			Christopher J. Calabrese
Brain loaned to:	AT&T Bell Laboratories, Murray Hill, NJ
att!ulysses!cjc		cjc at ulysses.att.com
Obligatory Quote:	``Anyone who would tell you that would also try and sell you the Brooklyn Bridge.''



More information about the Comp.lang.c mailing list