/*删除文件path1的第N行
return 0
success
-1 error
*/
int func(char* path1,int N)
{
char buf[1024]={0};
FILE* old = NULL;
FILE* new = NULL;
old = fopen(path1,"r");
new = fopen(path2,"r+");
for(i=0;i<N-1;i++){
if(NULL != fget(buf,1024,old))
{
fputs(buf,new);
}else{
return -1;
}
}
if(NULL == fget(buf,1024,old))
return -1;
while(NULL != fget(buf,1024,old))
{
fputs(buf,new);
}
remove(path1);
rename(path2,path1);
return 0;
}
[
本帖最后由 fogsky 于 2009-9-3 00:42 编辑 ]