Interface
#include <codecogs/io/binary/file_length.h>
using namespace IO::Binary;
| long | fileLength (FILE* stream) Calculates the length of a binary file. |
Function Documentation
Returns the length of a file in bytes. Useful when you need to dynamically allocate memory to hold the contents of
a file you intend to read. This function was designed to replicated the similarly named filelength function that
comes with some distributions of C/C++, particularly on DOS platforms. There doesn't appear to be an
equivalent in Unix.
Example:
#include <stdio.h>
#include <codecogs/io/binary/file_length.h>
using namespace IO::Binary;
int main ()
{
FILE* stream = fopen("/codecogs/io/binary/file_length.h","rb");
printf("\n File length=%d", fileLength(stream));
fclose(stream);
return 0;
}
Parameters:
| stream | A pointer to the file stream |
Returns:
- The length of the file in bytes. Return -1 if an error is encountered.
Authors:
- Will Bateman (March 2005)
Source Code:
-
Last Modified: 18 Oct 07 @ 17:07 Page Rendered: 2008-05-13 19:36:45
Page Comments
You must login to leave a messge