1

I want to read a file forever how can I go to the beginning of the file
Here is my code

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
}
Freak
  • 6,786
  • 5
  • 36
  • 54
Euler
  • 652
  • 3
  • 11
  • 24

2 Answers2

2

Take a look to fseek and SEEK_SET

Also note that

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

should be

uint8* buffer; 
uint32 nSize =1000;
buffer=(uint8*)malloc(nSize);
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
0

Following seems to work for you. Best of luck :)

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);
}
Ayse
  • 2,676
  • 10
  • 36
  • 61