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,721
  • 5
  • 35
  • 51
Euler
  • 642
  • 3
  • 11
  • 23

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
  • 37,819
  • 6
  • 48
  • 88
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,546
  • 9
  • 35
  • 58