2012-04-15 64 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懷疑。