user-0 提问: fseek为什么总时只移到末尾而不偏移？

回复:
user: user-1
content: 另一个需要注意的是 修改位置之后 写入操作不是插入是覆盖 原先内容  123 # 写入位置在#前面 写入w 结果是 123 w 而不是 123 w#

user: user-1
content: 和文件打开方式有关  如果是 打开模式带a 则只能在结尾添加数据 fseek对写入位置无效  只能修改读取位置  你不能正确定位问题 应该把代码完整的发出来  你的问题在fopen 而你只发了fseek

user: user-2
content: 我的回复被版主屡次误认为是灌水删除了，我再最后一次回复，货卖识家：  不要把 fopen("...","...");fscanf,fprintf,fgets,fgetc,fclose //读时把\r\n替换成\n，写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待 和 fopen("...","...b");fseek,ftell,fread,fwrite,fgetc,fclose //不作以上替换，遇到\x1a仍继续读;读写的内容当字节看待 弄混了  综上所述，fseek只能在fopen时带b时使用！

user: user-3
content: 每次看见这样没诚意的提问，总是想到看腿识鸟的梗，然后就没兴趣了。

user: user-2
content: 不要把 fopen("...","...");fscanf,fprintf,fgets,fgetc,fclose //读时把\r\n替换成\n，写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待 和 fopen("...","...b");fseek,ftell,fread,fwrite,fgetc,fclose //不作以上替换，遇到\x1a仍继续读;读写的内容当字节看待 弄混了  fopen时不带b 就不要fseek

user: user-0
content: 引用 9 楼 Minikinfish的回复:调用fseek，设置完文件指针，再fwrite写文件 书上说写正负都可以呀，而且可以负确实是向头方向移动字节。如果用fwrite可能不确定字符数比较麻烦

user: user-4
content: 调用fseek，设置完文件指针，再fwrite写文件

user: user-4
content: 引用 7 楼 脚踏实地丨仰望星空 的回复:[quote=引用 4 楼 Minikinfish的回复:]  SEEK_CUR  Current position of file pointer.  SEEK_END  End of file.  SEEK_SET  Beginning of file. 大佬，能否指点一下，看的不是很懂[/quote]   int fseek(     FILE *stream,    long offset,    int origin  );  SEEK_CUR  当前位置，偏移offset个字节 SEEK_END 文件末尾位置，偏移offset个字节（offset<=0） SEEK_SET 文件开始位置，偏移offset个字节（offset>=0）

user: user-0
content: 引用 4 楼 Minikinfish的回复:请看第三个参数  The fseek and _fseeki64 functions 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 a write. The argument origin must be one of the following constants, defined in STDIO.H:  SEEK_CUR  Current position of file pointer.  SEEK_END  End of file.  SEEK_SET  Beginning of 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. fseek and _fseeki64clears the end-of-file indicator and negates the effect of any prior ungetc calls against stream.  When a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. If no I/O operation has yet occurred on a file opened for appending, the file position is the start of the file. 大佬，能否指点一下，看的不是很懂

user: user-0
content: 引用 5 楼 脚踏实地丨仰望星空的回复:[quote=引用 3 楼 forever74的回复:]文件原来啥样 你想弄成啥样 你的代码啥样 文件变成啥样  从仅有的信息上看，一切都很正常，是你的预期或者说对文件操作的理解不对。 原来没有+wanan的部分，然后输入是+wanan那部分[/quote] 你好，我就是只打算插入到末尾#之前的，但插到后面了，就是这个问题

user: user-0
content: 引用 3 楼 forever74的回复:文件原来啥样 你想弄成啥样 你的代码啥样 文件变成啥样  从仅有的信息上看，一切都很正常，是你的预期或者说对文件操作的理解不对。 原来没有+wanan的部分，然后输入是+wanan那部分

user: user-4
content: 请看第三个参数  The fseek and _fseeki64 functions 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 a write. The argument origin must be one of the following constants, defined in STDIO.H:  SEEK_CUR  Current position of file pointer.  SEEK_END  End of file.  SEEK_SET  Beginning of 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. fseek and _fseeki64clears the end-of-file indicator and negates the effect of any prior ungetc calls against stream.  When a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. If no I/O operation has yet occurred on a file opened for appending, the file position is the start of the file.

user: user-3
content: 文件原来啥样 你想弄成啥样 你的代码啥样 文件变成啥样  从仅有的信息上看，一切都很正常，是你的预期或者说对文件操作的理解不对。

user: user-5
content: 这个写只能先修改内存里，然后重新刷写文件（磁盘orflash)。不能在文件里直接插入～

user: user-2
content: 不要把 fopen("...","...");fscanf,fprintf,fgets,fgetc,fclose //读时把\r\n替换成\n，写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待 和 fopen("...","...b");fseek,ftell,fread,fwrite,fgetc,fclose //不作以上替换，遇到\x1a仍继续读;读写的内容当字节看待 弄混了