0

I have a binary file and I want to read all of them. I thought, I should find its size and use fread function but I cant find the size. Do you have any idea?

size_t size, size_begin, size_end;

size_begin = fseek(dir_file, 0, SEEK_END);
size_end = fseek(dir_file, 0, SEEK_SET);

size = size_end - size_begin;
alk
  • 69,737
  • 10
  • 105
  • 255
Meliz Ersoy
  • 15
  • 1
  • 2
  • 4
    Did you search? There are many duplicate questions, asking this. [Here's one](http://stackoverflow.com/questions/8236/how-do-you-determine-the-size-of-a-file-in-c). [Here's another.](http://stackoverflow.com/questions/238603/how-can-i-get-a-files-size-in-c/238607) – Darren Stone Dec 24 '13 at 17:29
  • 1
    Look at `ftell` or the duplicates... – Floris Dec 24 '13 at 17:29
  • Do oyu like to tell us what isn't working? – alk Dec 24 '13 at 17:35
  • Also, if the file is large, you probably don't want to read the entire thing at once... – twalberg Dec 24 '13 at 17:48
  • 1
    Standard does not require that it be treated as a meaningful SEEK_END for binary stream. – BLUEPIXY Dec 24 '13 at 17:51
  • 1
    _Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has undefined behavior for a binary stream (because of possible trailing null characters) or for any stream with state-dependent encoding that does not assuredly end in the initial shift state_ – BLUEPIXY Dec 24 '13 at 17:57
  • @BLUEPIXY Does it mean that C provides no portable way to obtain file size containing binary stream (i.e. binary file)? – pmor Nov 11 '22 at 14:30

0 Answers0