读书人

关于写文件时出错的有关问题

发布时间: 2013-03-14 10:33:15 作者: rapoo

关于写文件时出错的问题


int temp[4]={0};
fseek(p_file_index,-16,SEEK_END);
fread(temp,16,1,p_file_index);
temp[0]=strlen(p_html_title_seat)+temp[0];
fseek(p_file_index,0,SEEK_END);
fwrite(temp,16,1,p_file_index);

其中p_html_title_seat是不同的字符串,然后FILE* p_file_index存储字符串的累积长度。
运行结果前面正常,到了中间就出错了,所有的都往右移位了,这是怎么回事?求大神啊 文件存储问题
[解决办法]
看这段没有问题,能再贴全一点吗?
[解决办法]
我也没看出来错误

引用:
引用:看这段没有问题,能再贴全一点吗?C/C++ code?12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747……

[解决办法]
整型数据不能直接用fwrite写的,因为fwrite是对文件进行二进制操作,会把整数当成ascii码值写入的。
[解决办法]
When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek or rewind, but is always moved back to the end of the file before any write operation is carried out. Thus, existing data cannot be overwritten.

读书人网 >C语言

热点推荐