Thread: Emergency

  1. #1
    Banned
    Join Date
    Mar 2006
    Posts
    8

    Question Emergency

    hi all,
    i have a question and i have only 48 hours to finish this project,
    i have a binary file that i nned to contains some information, i need to store this information in an array of the file size...so simply...how can i determine the size of a binary file in C
    thanks

  2. #2
    Banned
    Join Date
    Mar 2006
    Posts
    8
    please try to send me code

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Open the file in binary read mode
    Read and count one byte at a time
    When you hit EOF, you're done.

    And why should we send you code? Can you afford to pay an independant consultant for programming services?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here, I'll send you "some code", you can do the rest.
    Code:
    int main( void )
    {
        return 0;
    }
    There's some. It will even compile and run.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    7

    stdio.h

    Just look up what is availible to you in stdio.h.

    guidance.txt is a file in the same directory as the executable. This could definetly use come cleaning up to be functional, but I figure it gets the concept across.

    Code:
    #include <stdio.h>
    
    int main()
    {
            FILE *fd;
            int size;
    
            fd=fopen("guidance.txt", "rb");
    
            fseek (fd, 0, SEEK_END);
            size=ftell(fd);
            fclose(fd);
    
            printf("guidance.txt is %i bytes long\n", size);
    
            return 0;
    }

  6. #6
    Banned
    Join Date
    Mar 2006
    Posts
    8
    breik : thank you very much man, i was looking for fseek i did not know how to use it...thanks alot

    quzah: your code is just like your brain...void...doesnt return anything...you figure out the rest

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by taha54
    quzah: your code is just like your brain...void...doesnt return anything...you figure out the rest
    Actually... it returns 0....

    ...and insulting a senior member doesn't make up for asking someone to do your homework for you on this forum. I know, it's hard to adapt to all these crazy rules.
    Sent from my iPadŽ

  8. #8
    Banned
    Join Date
    Mar 2006
    Posts
    8
    that was not a homework to let you know, ok

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It wasn't urgent either
    http://www.catb.org/~esr/faqs/smart-...ns.html#urgent

    But it is closed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plz help me make my assigment more bulletproof
    By joker_tony in forum C Programming
    Replies: 4
    Last Post: 03-28-2008, 09:03 PM
  2. Emergency help for the problem !!!
    By chelp151 in forum C Programming
    Replies: 7
    Last Post: 04-22-2007, 12:09 PM
  3. Emergency 2
    By newuser21 in forum C Programming
    Replies: 3
    Last Post: 03-12-2006, 09:04 AM
  4. Please help me with this !! Emergency
    By newuser21 in forum C Programming
    Replies: 1
    Last Post: 03-12-2006, 07:22 AM
  5. another novice need some emergency help
    By KarateKid in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2001, 11:09 PM