Could you explain following code?
str = (char *) malloc (sizeof(char) * (num+1));
malloc
malloc allocates memory.
num+1 as num is the number of characters in the string and +1 for the null terminator