The code currently does this and the fgetpos does handle files larger than 4GB but the seek returns an error, so any idea how to seek to the end of a file >4GB?
fpos_t currentpos;
sok=fseek(fp,0,SEEK_END);
assert(sok==0,"Seek error!");
fgetpos(fp,¤tpos);
m_filesize=currentpos;
...
            
           
          
            
            I have a situation in a code where there is a huge function that parses records line-by-line, validates and writes to another file.
In case there are errors in the file, it calls another function that rejects the record and writes the reject reason. 
Due to a memory leak in the program, it crashes with SIGSEGV. One solution to kind of ...
            
           
          
            
            Is using fseek to backtrack character fscanf operations reliable?
Like for example if I have just fscanf-ed 10 characters but I would like to backtrack the 10 chars can I just fseek(infile, -10, SEEK_CUR) ? 
For most situations it works but I seem to have problems with the character ^M. Apparently fseek registers it as a char but fscan...
            
           
          
            
            Hi,
What I need is an equivalent for PHP's fseek() function. The function works on files, but I have a variable that contains binary data and I want to work on it. I know I could use substr(), but that would be lame - it's used for strings, not for binary data. Also, creating a file and then using fseek() is not what I am looking for ei...
            
           
          
            
            As I loop through lines in file A, I am parsing the line and putting each string (char*) into a char**. 
At the end of a line, I then run a procedure that consists of opening file B, using fgets, fseek and fgetc to grab characters from that file. I then close file B.
I repeat reopening and reclosing file B for each line.
What I would ...
            
           
          
            
            My previous Question is about raw data reading and writing, but a new problem arised, it seems there is no ending....
The question is: the parameters of the functions like lseek() or fseek() are all 4 bytes. If i want to move a span over 4G, that is imposible. I know in Win32, there is a function SetPointer(...,Hign, Low,....), this  po...
            
           
          
            
            
  Q:      I'm trying to update a file in
  place, by using fopen mode "r+",
    reading a certain string, and writing
  back a modified string,   but it's not
  working.
  
  A:      Be sure to call fseek before
  you write, both to seek back to the
    beginning of the string you're trying
  to overwrite, and because   an fseek
  or ff...
            
           
          
            
            I have a file. I read the size of file. Then I loop reading two bytes at a time until I get to the end of the file. After every read operation I increment the current position by 2, however the position does not get incremented after I get to half the size of the file, the fread operation will read 0 bytes.
the program reads the file si...
            
           
          
            
            Hi there,
we have a C++ class which basically reads and writes vectors from a binary file. An exemplary read function that loads a single vector into memory looks like this:
int load (const __int64 index, T* values) const {
 int re = _fseeki64(_file, index * _vectorSize + _offsetData, SEEK_SET); 
 assert(re == 0);
 size_t read = frea...
            
           
          
            
            I'm trying to read the last 50 characters in a file by doing this:
FILE* fptIn;
char sLine[51];
if ((fptIn = fopen("input.txt", "rb")) == NULL) {
    printf("Coudln't access input.txt.\n");
    exit(0);
}
if (fseek(fptIn, 50, SEEK_END) != 0) {
    perror("Failed");
    fclose(fptIn);
    exit(0);
}
fgets(sLine, 50, fptIn);
printf("%s", ...
            
           
          
            
            This is not a pure programming question, however it impacts the performance of programs using fseek(), hence it is important to know how it works. A little disclaimer so that it doesn't get closed.
I am wondering how efficient it is to insert data in the middle of the file. Supposing I have a file with 1MB data and then I insert somethi...
            
           
          
            
            Can you set any index of array as starting index i.e where to read from file? I was afraid if the buffer might get corrupted in the process.
#include <stdio.h>
int main()
{
    FILE *f = fopen("C:\\dummy.txt", "rt");
    char lines[30]; //large enough array depending on file size
    fpos_t index = 0;
    while(fgets(&lines[index], ...
            
           
          
            
            How do I read a file backwards line by line using fseek?
code can be helpful. must be cross platform and pure php.
many thanks in advance
regards
Jera
...
            
           
          
            
            how do I do this.
the file can get very big, so good performance is necessary
code is helpful.
this is what i have so far
function prepend($string, $filename) { 
    $context = stream_context_create (); 
    $fp = fopen($filename,'r',1,$context); 
    $tmpname = md5($string); 
    file_put_contents($tmpname,$string); 
    file_put_co...
            
           
          
            
            I require to add a string before 45byte in an existing file. I tried using fseek as bellow.
int main()
{
 FILE *fp;
 char str[] = "test";     
 fp = fopen(FILEPATH,"a");
 fseek(fp,-45, SEEK_END);                
 fprintf(fp,"%s",str);
 fclose(fp);     
 return(0);
}
I expected that this code will add "test" in before 45 char from EOF...
            
           
          
            
            I have a process master that spawns N child processes that communicate with the parent through unnamed pipes. I must be able to:
make the father open the file and then send, to each child, a struct telling that it has to read from min to max line;
this is going to happen at the same time, so I don't know:
1st how to divide total_lines ...
            
           
          
            
            I am trying to find how to store and process (search, add, remove) an array of linked lists on disk. For example in memory, it would like
struct list {
 int a;
 struct list *next;
}LIST
LIST *array[ARRAY_SIZE]
int main{
...
 LIST *foo = array[pointer];
 /* Search */
 while(foo!=NULL){
   ...
   foo=foo->next
 }
}
I believe that by ...
            
           
          
            
            I have a binary file in CSV format that contains multiple records. Each record is entered in as user_name, last_name, first_name, num_wins, num_losses, num_ties.  I am creating a method to update a certain players record of wins,losses and ties. The user inputs the username to change followed by the changes to the wins, losses and ties. ...