The first problem is that code is a pointer returned from malloc() and you are incrementing it therby losing the start of you allocation. Not good. I would assign code to a temp pointer in increment it. Secondly, the de-reference operatot an the incrment operator have the same precedence and are associated right to left. So *code++ will increment code and ...