This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/Lectures/LC18/FileSize/filesize.c

38 lines
781 B
C
Raw Permalink Normal View History

2022-04-07 15:58:01 +00:00
#include <stdio.h>
#include <stdlib.h>
/* Example 3 - jumping & getting element count */
int main()
2022-04-07 15:58:01 +00:00
{
long FileBytes;
FILE *fptr;
/* Open the file from example 1 */
fptr = fopen ("data.dat","rb");
if ( fptr == NULL )
{
printf ("\nError opening input file - aborting ");
exit (0);
}
/* Move to the end of file */
fseek (fptr, 0, SEEK_END);
/* Get the byte size */
FileBytes = ftell(fptr);
/* Convert to size based on fact all int's */
FileBytes = FileBytes / sizeof(int);
/* Display the read value */
printf ("No. of items in file is %ld\n",FileBytes);
2022-04-07 15:58:01 +00:00
/* And close */
fclose (fptr);
/* All Done */
return 0;
}