Thanks for the hack! I ran this on my computer and as you said it is giving the desired output.
And Yes, I agree that array will be overwritten, that's what I thought first and then I thought, something else and convinced.

For this kind, what will be the suggestion to fix? I tried with struct (I am not much into this, but have reference code) as posted in post #1, I am getting malloc undefined reference. SO I cannot use malloc and free()