2013-07-02 65 views
1

我想讀取文件永遠我怎麼能去到文件的開頭
這裏是我的代碼轉至文件的開頭

FILE* inp_file=fopen("Input_file.bin","rb"); 
uint8* buffer; 
buffer=(uint8*)malloc(nSize); 
uint32 nSize =1000; 
while(1) 
{ 
    while(! feof (inp_file)) 
    {    
     memset (buffer,'0',nSize); 
     fread (buffer,nSize,1,inp_file); 
     Sleep(5); 
    } 
    //Here I want to go to the beginning of the file 
} 
+1

http://stackoverflow.com/questions/5431941/while-feof-file-is-always-wrong –

+2

'男人fseek' ... –

+2

使用'無效倒帶(FILE *流');' –

回答

2

看看到fseekSEEK_SET

還要注意的是

uint8* buffer; 
buffer=(uint8*)malloc(nSize); 
uint32 nSize =1000; 

應該

uint8* buffer; 
uint32 nSize =1000; 
buffer=(uint8*)malloc(nSize); 
+0

謝謝順便說一句,這是一個錯字錯誤 – Euler

0

以下似乎適合你。祝您好運:)

FILE* inp_file=fopen("Input_file.bin","rb"); 
uint8* buffer; 
buffer=(uint8*)malloc(nSize); 
uint32 nSize =1000; 
while(1) 
{ 
    while(! feof (inp_file)) 
    {    
     memset (buffer,'0',nSize); 
     fread (buffer,nSize,1,inp_file); 
     Sleep(5); 
    } 
    rewind(inp_file); 
}