+ 2
After inserting, the str length will increases by 1 so you need to track that also in loop.
+ 2
Manav Roy
How about this?
https://code.sololearn.com/cvO2jZ2Wsqaz/?ref=app
it is not very robust though. It fails on some negative numbers.
It is suggested to use <locale.h> for more specific separators, like in India.
+ 1
Manav Roy Are you sure,?
You don't having camma inserted so is not it increase length?
See 1000 (len=4) after insert 1,000 (len=5, with camma added)...!