注册 登录
编程论坛 C语言论坛

CRC32的计算程序,为啥结果不对啊?

chaw899 发布于 2019-07-14 00:23, 1829 次点击
static unsigned int crc32( const unsigned char *buf, unsigned int size);
{
  ...... // 这里就省略了
}

定义如下


   int main(int argc, char *argv[])
{
   FILE * fp;
   unsigned int res;
   unsigned char buf[MAXLEN];
   fp = fopen("tu.mp3", "r" );
   if( crc32 == NULL )
   {
       printf("File is not exist.\n");
       exit(1);
   }
    int rc;   // 这里每次读入1024字节,最后一个是余数,采用分段计算的方法,为啥结果不对啊?
//  fseek(infile,0x4b,SEEK_SET);
    while( (rc = fread(buf,sizeof(unsigned char), MAXLEN,fp)) != 0 )
    {
       res = crc32(buf,rc);
    }   
     printf("%16X",res);
     fclose(fp);
     return 0;
}

2 回复
#2
吹水佬2019-07-14 04:34
   fp = fopen("tu.mp3", "r" );
   if( crc32 == NULL )
   {
       printf("File is not exist.\n");
       exit(1);
   }
这段代码是什么意思?
#3
chaw8992019-07-14 07:32
我计算的是tu.mp3这个文件的crc32的值。判断当前路径是否存在tu.mp3,不
存在的话,程序就退出了。
1