Created
December 20, 2011 22:47
-
-
Save tsterker/1503664 to your computer and use it in GitHub Desktop.
[c] Get filesize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Returns file size in BYTES */ | |
int file_sizeof(FILE *fp) | |
{ | |
int filesize; | |
fseek(fp, 0L, SEEK_END); /* jump to end of file */ | |
filesize = ftell(fp); /* current byte of file == filesize */ | |
rewind(fp); /* jump to beginning of file */ | |
return filesize; | |
} | |
int main(){ | |
FILE *fp; | |
char *filename = "file.dat"; | |
int filesize; | |
fp = fopen(filename,"wb") /* check if not NULL */ | |
filesize = file_sizeof(fp); | |
printf("size of %s is %d\n", filename, filesize); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment