Whoever asked you to cast malloc was misdirecting you. Note that you NEED to cast malloc() if you are compiling C code in a C++ environment, but you also have to abide to a whole range of other rules then. Do not compile pure C code with a C++ compiler.
Edit: It should be noted that for example Visual Studio C++, although it is called C++, can also compile C code without any problem at all - all you have to do is call the file something.c instead of something.cpp [or you can force the issue by using the correct /Tp or /Tc (from memory) flags in the compiler options].
--
Mats