[prog] simple c++ question

Jimen Ching jching at flex.com
Sun Jun 22 15:58:44 EST 2003


On Sun, 22 Jun 2003, Laurel Fan wrote:
>If you want to do it this way, you have essentially 2 choices:
>
>1. allocate the memory in main() first, then, in readText, copy the
>tokenized string into your preallocated array.
>
>2. allocate the memory using malloc() in readText(), and set the
>pointers to your allocated memory.

3. make tempText static in readText.  Of course, this will prevent using
readText from multiple threads.  But strtok is not thread-safe either.  So
using 'static' is ok.

I should note, using <cstring> is not very object oriented nor C++.  The
standard C++ library string class is very powerful, and has capabilities
to do the things you want.  But I don't know the purpose behind using
strtok and friends.  So I can't say if going straight OO is the correct
path.

--jc
-- 
Jimen Ching (WH6BRR)      jching at flex.com     wh6brr at uhm.ampr.org


More information about the Programming mailing list