1) What I mean is don't cast whatever malloc returns.
some_ptr = malloc(blah);
some_ptr = (some_ptr*)malloc(blah);
2) fflush(stdin) is UNDEFINED behaviour, don't use it.
3) Fix the issues I pointed out in my previous post before continuing. When you don't know, Google, then come here to ask if you couldn't find your answer.