我想从文件中读取字节然后重写它们。我确实喜欢这样:
FILE *fp;
int cCurrent;
long currentPos;
/* check if the file is openable */
if( (fp = fopen(szFileName, "r+")) != NULL )
{
/* loop for each byte in the file crypt and rewrite */
while(cCurrent != EOF)
{
/* save current position */
currentPos = ftell(fp);
/* get the current byte */
cCurrent = fgetc(fp);
/* XOR it */
cCurrent ^= 0x10;
/* take the position indicator back to the last position */
fseek(fp, currentPos, SEEK_SET);
/* set the current byte */
fputc(cCurrent, fp);
}
在文件上执行代码后,文件的大小在无限循环中增加。
我的代码有什么问题?