我有这段代码,但它在第 5 行(fseek)中抛出错误。
int cmpFILEd(void *aa,void *bb){
int size1,size2;
FILE *a=(FILE*)aa;
FILE *b=(FILE*)bb;
fseek(a,0,SEEK_END);
fseek(b,0,SEEK_END);
size1=ftell(a);
size2=ftell(b);
if(size1==size2)
return 0;
else if(size1>size2)
return 1;
else
return -1;
}
这段代码有什么问题?
_
编辑:错误:
First-chance exception at 0x77052865 (ntdll.dll) in cFILE.exe: 0xC0000008: An invalid handle was specified.
If there is a handler for this exception, the program may be safely continued.
最佳答案
鉴于:
1) OP“...不能改变它对通用性的需求。”
2) int cmpFILEd(void *aa,void *bb)
是一个比较函数
这看起来像是 qsort()
等格式错误的比较函数。
在那种情况下,传递的指针是 FILE *
的地址,正如@BLUEPIXY 所建议的那样,
int cmpFILEd(void *aa,void *bb){
long size1, size2; // Note use long here
FILE *a = *((FILE**) aa);
FILE *b = *((FILE**) bb);
...
关于按大小比较 C 中的 2 个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24588106/