There is no need to malloc.
There is no need to have a variable buffer size.

char buff [BUFSIZ];
And your inner loop will do just fine.