Not to mention that you don't need to cast malloc() and that sizeof(char) is always 1.