It looks like o will never get incremented so you just stay in this loop until you run out of disk space. for (o=1;o<=noption;1) I think you want something like for (o=1;o<=noption;o+=1)