Could you explain following code?
str = (char *) malloc (sizeof(char) * (num+1));
malloc
sizeof(char)
is safe. One shouldn't assume a single byte per character.
My question is what are you doing programming if you don't know what malloc does?
man malloc
on a Linux system. On Windows. who knows? Probably 17 mouse clicks.