2012-06-26 131 views
0

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

该文件的大小存储在一个无符号的long变量中。有谁能够帮助我?

我使用Borland C++

+0

伙计,不要给他负面回购,他是一个新手...相反,提供输入..!谢谢。 –

+0

分享你已经试过的代码,并且还提到你面临的是什么样的问题 –

+0

http://stackoverflow.com/q/621425/143897阅读这个问题的答案 –

回答

0

试试这个。自从我触及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... 
}