Home > Back-end >  Fseek why always moved to the end and not only when migration?
Fseek why always moved to the end and not only when migration?

Time:01-06

Every time is, no matter how many byte offset, why not move to # before writing, please? Writing is wanananan that paragraph,

CodePudding user response:

This writing can only modify memory first, and then to flash files (disk orflash), cannot be directly inserted into the ~ in the file

CodePudding user response:

File originally what
Do you want to get into what
Your code is what
File into what

Only information from point of view, everything is normal, is your expectations or wrong understanding of file operations,

CodePudding user response:

Please look at the third parameter

The fseek and _fseeki64 functions provides The moves The file pointer (if any) associated with stream to a new location that is offset bytes from origin. The next operation on The stream takes place at The new location. On a stream open for update, The next operation can be either a read or write. "The argument of origin must be one of The following constants, defined in The STDIO, H:

SEEK_CUR
The Current position of the file pointer.

SEEK_END
The End of the file.

SEEK_SET
Beginning of the file.

You can use fseek and _fseeki64 to reposition the pointer anywhere in a file. The pointer can also be positioned beyond the end of the file. The fseek and _fseeki64clears the end - of - file indicator and negates the effect of any prior ungetc calls against the stream.

When a file is the opened for appending data to the current file position is determined by the last I/O operation, not by the where the next write order to occur. If no I/O operation has yet occurred on a file the opened for appending, the file position is the start of the file.

CodePudding user response:

reference forever74 reply: 3/f
file originally what
Do you want to get into what
Your code is what
File into what

Only information from point of view, everything is normal, is your expectations or wrong understanding of file operations,

No original + wanan part, and then input is + wanan that part

CodePudding user response:

refer to fifth floor down-to-earth 丨 look up at the starry sky response:
Quote: reference forever74 reply: 3/f
file originally what
Do you want to get into what
Your code is what
File into what

Only information from point of view, everything is normal, is your expectations or wrong understanding of file operations,

No original + wanan part, then enter that part is + wanan

Hello, I'm just going to insert to the end # before, but in the behind, is the problem

CodePudding user response:

reference 4 floor Minikinfish response:
please see the third parameter

The fseek and _fseeki64 functions provides The moves The file pointer (if any) associated with stream to a new location that is offset bytes from origin. The next operation on The stream takes place at The new location. On a stream open for update, The next operation can be either a read or write. "The argument of origin must be one of The following constants, defined in The STDIO, H:

SEEK_CUR
The Current position of the file pointer.

SEEK_END
The End of the file.

SEEK_SET
Beginning of the file.

You can use fseek and _fseeki64 to reposition the pointer anywhere in a file. The pointer can also be positioned beyond the end of the file. The fseek and _fseeki64clears the end - of - file indicator and negates the effect of any prior ungetc calls against the stream.

When a file is the opened for appending data to the current file position is determined by the last I/O operation, not by the where the next write order to occur. If no I/O operation has yet occurred on a file the opened for appending, the file position is the start of the file.

Bosses, it can see is not very good

CodePudding user response:




refer to 7th floor down-to-earth 丨 look up at the starry sky response:
Quote: refer to 4th floor Minikinfish response:


SEEK_CUR
The Current position of the file pointer.

SEEK_END
The End of the file.

SEEK_SET
Beginning of the file.

Bosses, it can see is not very good



Int fseek (
The FILE * stream,
Long offset,
Int origin
);

SEEK_CUR, the current position offset offset bytes
SEEK_END, the end of the file position offset offset bytes (offset<=0)
SEEK_SET file starting position, offset offset bytes (offset>=0)

CodePudding user response:

Call fseek, set the file pointer, and then write file fwrite

CodePudding user response:

references 9 f Minikinfish response:
call fseek, set the file pointer, and then write file fwrite

Said plus or minus the book can be ah, but also negative is moving in the direction of head bytes, if using fwrite may not determine the number of characters more troublesome
  • Related