size of a file

This is a discussion on size of a file within the C Programming forums, part of the General Programming Boards category; Hi all, Other than using m = lseek(fildes, 0, 2) to find out the size of a file, do you ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    30

    size of a file

    Hi all,

    Other than using m = lseek(fildes, 0, 2) to find out the size of a file, do you know other ways of doing it?

    Thanks..

  2. #2
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    Another option (instead of typing out the code, i ripped it off google )

    Code:
        #include <sys/stat.h>
        ...
        struct stat results;
        
        if (stat("input.bin", &results) == 0)
            // The size of the file in bytes is in
            // results.st_size
        else
            // An error occurred

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21