2012-04-15 39 views
0

用下面的代码,我试图从文件中读取4个字节:误差FSEEK

FILE *f 

uint32_t read_program(int A) 
{ 
    long i; 
    uint32_t strofprog; 
    uint8_t tmp; 
    i = 4*A; 
    fseek(f,i,0);// set a position in file 
    if((tmp = getc(f)) != EOF) 
    { 
     while((i%(4*A)) < 4) 
     { 
      fseek(f, i, SEEK_SET); 
      tmp = getc(f); 
      strofprog = tmp; 
      strofprog <<= 8; 
      i++; 
     } 
     return strofprog; 
    } 
    else 
    { 
     fclose(f); 
     return -1; 
    }; 
} 

然而,当我运行它,它会导致以下错误:

main.c: In function ‘read_program’: 
main.c:77: error: incompatible type for argument 1 of ‘fseek’ 
/usr/include/stdio.h:722: note: expected ‘struct FILE *’ but argument is of type ‘FILE’ 

什么我做错了,我该如何解决? 85

+4

这是真码吗?检查'f'的声明。 – littleadv 2012-04-15 10:25:17

+0

是的。 f的声明是FILE * f;那么f = fopen(“file.bin”,“r”); – Ivan 2012-04-15 10:33:12

+1

'if((tmp = getc(f))!= EOF)'只有在'tmp'被声明为'int'时才是正确的!你的内部循环也不检查'tmp'是否是'EOF'或者是 – Anthales 2012-04-15 10:37:07

回答

2

线在贴:

fseek(*f,i,0);// set a position in file 

由@unwind怀疑。