09-23-04 02:21 AM
M=E5ns Rullg=E5rd said the following, on 09/17/04 19:39:
> RJGraham <null@null.com> writes:
>=20
>=20
In addition to what M=E5ns has told you, you also need to insert here:
#include <stdlib.h>[vbcol=seagreen]
ue)[vbcol=seagreen]
>=20
>=20
And you should not cast the returned value of malloc, but you should=20
check that it is not NULL. The returned value from malloc is of type=20
"pointer to void", which can be converted into any object pointer.
If (because stdlib.h is not #included) there is no prototype in scope=20
for malloc, it is assumed to return 'int' by default. Although it is=20
true on many platforms that you can go between 'int' and pointer types=20
without trouble, it is _not_ always true (and certainly is not=20
guaranteed in standard C). The presence of the cast will usually=20
prevent the compiler from warning you of a potential problem.
> strtok_r modifies the value of buf, hence the need for the double
> pointer. You should save the original value somewhere and pass that
> to free().
>=20
>=20
>=20
>=20
--=20
Rich Gibbs
rgibbs@alumni.princeton.edu
[ Post a follow-up to this message ]
|