我正在尝试计算已编译文件中的字符,但我无法到达最后一个字符。这是我的测试代码,其中 SEEK_END 停止在某个点(我不知道为什么)并且文件的其余部分仍未读取。
源代码是使用 make 编译的。
您可以使用 GHex 查看/编辑编译文件。
我的示例:
- 原始编译文件:https
://gist.github.com/anonymous/58aa85dac60047f4adeb - SEEK_END 之前的输出:https ://gist.github.com/anonymous/6b1ab0b2dc3589a4d910
unsigned char *buffer = (unsigned char*) malloc(sizeof (unsigned char));
fseek(f, 0, SEEK_SET); // move the file indicator to first char
fseek(f, 0, SEEK_END); // move the file indicator to the end of file
long ss = ftell(f); // get number of bytes
fseek(f, 0, SEEK_SET); // move the file indicator to first char
int run = 1;
long p = 0;
while (run) {
fseek(f, 0, SEEK_CUR); // indicator to the next char
fread(buffer, 1, 1, f); // put value into buffer
p = ftell(f); // check the length of bytes
if (p == ss - 1) { // if is the end of file
FILE *f3; // opened the file again
f3 = fopen(filename, "rb");
fseek(f3, ss-10, SEEK_CUR); // move the indicator to the ss-10
int jj = 1;
for (jj; jj < 400; jj++) { // read after the SEEK_END of file but nothing happens
fseek(f3, 0, SEEK_CUR);
fread(buffer, 1, 1, f3);
ferror(f3);
}
}
}
谢谢 !:)