Thread: Reading a binary file like a matrix of ints

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well you've got num, right? That's your array. num[0] is the first number, num[1] is the second number, etc.

    The only difficulty is that four bytes may or may not even get you one number, depending on your system. You should make your buffer as big as you need it.

    There's also no good reason for you to make your buffer of type char.
    Code:
    int big_pile_of_numbers[1000];
    file.read(reinterpret_cast<char*>big_pile_of_numbers, sizeof(big_pile_of_numbers));

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    52

    what if the buffer isn't completely full?

    How could I tell that the buffer is completely full or more like when it isn't completely full as there were no 1000 numbers, how can I prevent myself from accessing garbage locations?

    Ted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  2. Reading from binary file; fread problems?
    By pmgeahan in forum C Programming
    Replies: 3
    Last Post: 01-15-2009, 05:07 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. Reading data from a binary file
    By John22 in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 02:00 PM