I am confused that why it take more time when file size let see is 100000 even for first iteration that run very efficiently in case of 10,000.
For Exampe: I put printf statement for each iteration. In case of 10,000 first iteration take let say less then a milli second. where as in case of 100000 strings even the first iteration will take more then 30 second to print and so on. Why it could be slow like that?


Quote Originally Posted by laserlight View Post
Ah, then you should keep track of it, and only realloc when you need a longer length than has already been allocated. This way, you avoid allocating memory on each iteration, in exchange for a bit of housekeeping to decide when to reallocate.