Reading an unsigned long from a file

This is a discussion on Reading an unsigned long from a file within the C Programming forums, part of the General Programming Boards category; How come:- unsigned long lFrames; FILE *fp; fp = fopen("data.dat", "rb"); fread(&lFrames, sizeof(unsigned long), 1, fp); fclose(fp); Doesn't work?...

  1. #1
    Unregistered
    Guest

    Angry Reading an unsigned long from a file

    How come:-

    unsigned long lFrames;
    FILE *fp;

    fp = fopen("data.dat", "rb");
    fread(&lFrames, sizeof(unsigned long), 1, fp);
    fclose(fp);

    Doesn't work?

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    It works for me. Are you sure the number is stored as an unsigned long in the file and not a character. If the number is stored as characters, your code will read sizeof(long) characters from the file which will not be what your looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Heap corruption using zlib inflate
    By The Wazaa in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2007, 01:43 PM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 06:59 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM

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