4
#include <Windows.h> 
#include <stdio.h> 

int count = 0; 
FILE* pFile = 0; 
long Size = 0; 

void *memfrob(void * s, size_t n) 
{ 
    char *p = (char *) s; 

    while (n-- > 0) 
        *p++ ^= 42; 
    return s; 
} 

int main() 
{ 
    fopen_s(&pFile, "***", "r+"); 
    fseek(pFile, 0, SEEK_END); 
    Size = ftell(pFile); 
    char *buffer = (char*)malloc(Size); 
    memset(buffer, 0, Size); 
    fread(buffer, Size, 1, pFile); 
    fclose(pFile); 
    memfrob(buffer, Size); 
    fopen_s(&pFile, "***", "w+"); 
    fwrite(buffer, Size, 1, pFile); 
    fclose(pFile); 
}

嗨, fread 没有从文件读取任何内容到缓冲区,我不知道为什么。有人可以给我一个提示或推动正确的方向吗?

4

2 回答 2

11

在 fread 之前,您需要回到文件的开头。

于 2010-09-19T00:19:50.507 回答
4

您对文件末尾进行了 fseek,并且在执行 fread 之前没有 fseek 回来。

于 2010-09-19T00:20:41.580 回答