Thanks, that worked like a charm and thanks for the tips about realloc as well. I sometimes tend to assume that the functions I call will always work!! But out of curiosity, is there any reason the EOF method should not work? I mean is there any error in the code that I came along with. Shouldn't it work and the loop terminate when EOF is hit?