需要一些帮助阅读文件

Need some Help Reading File

本文关键字:文件 帮助      更新时间:2023-10-16

我需要读取一个文件(不是在二进制模式下)。我已经有了一个代码来知道文件的大小,我正在寻找的是如何通过=(文件大小)-8276字节读取文件。这些已读取的字节将存储在变量中,我需要写入它。

文件的大小存储在无符号长变量中。有人可以帮助我吗?

我使用博兰德C++

试试这个。自从我接触 Borland 以来已经有一段时间了,所以语法可能有点不对劲。将其视为伪代码,但您了解了概念。

// assuming you've already created the file handle.
HANDLE fileHandle;
unsigned long fileSize;
unsigned long numBytesRead;
bool result;
// get the file size
fileSize = GetFileSize(theFile, NULL);
// check to see if filesize is greater than 8276 bytes.
// if so, read (fileSize - 8276)
if(fileSize >= 8276)
{
result = ReadFile(fileHandle, &objectYouAreReadingItTo, (fileSize - 8276), numBytesRead);
}
else
{
  //...handle when fileSize is less than 8276 bytes...
}