Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to seek to the end of file to determine the file size?

Tags:

c

filesize

seek

I'm trying to get file size in c programming using seek. I can't use fseek, stat.size nor ftell, there's a custom operating system UNIX in which I need to run.

How can I find out filesize just by using seek? Is it possible?

  FILE *fd = open(argv[1], "r");

  if(fd == NULL)
  {
    printf("Not able to open the file : %s\n", argv[1]);
    return;
  }

  // Set the pointer to the end
  seek(fd, 0, SEEK_END);
like image 842
Abhilash Muthuraj Avatar asked Oct 22 '25 05:10

Abhilash Muthuraj


1 Answers

seek? You mean lseek probably. Have a look at the manual page. What does lseek return?

like image 124
Nordic Mainframe Avatar answered Oct 24 '25 21:10

Nordic Mainframe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!