问题出在
q=fopen("2.c","wb");
fseek(p,0,2);
fseek(p,-1,1);
while(ftell(p)>=0)
这几句.
fseek会把文件结束符清除掉,请看linux man page里面的一句话:
A successful call to the fseek() function clears the end-of-file indicator for
the stream and undoes any effects of the ungetc(3) function on the same stream.
所以你的while会无限循环了.