Converted some C++ code to C code