Thread: Writing array, to file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    Writing array, to file

    Hi,

    could someone please point me in the right direction here.

    Basically what i want to do it have a very fast key to value (int32=>int32) lookup which can be written to and stored in a binary file. I think similar to writing a hash table to a file.

    I'm not really sure how to explain it, but i would like to do something like this (i know this won't work)

    Code:
      
         int my_array[3];
    
         my_array[1] = 34;
         my_array[284] = 848;
         my_array[any_random_number] = 90;
    
         fwrite(&my_array, sizeof(int)*3, file);
    Code:
     
        /* Now Read Array Back */
    
        int array_read[3];
        fread(&array_read, sizeof(int)*3, file);
        print("array_read[284] has a value of 848);

    Does anyone know how this could be achieved? Thanks
    Last edited by zootreeves; 09-07-2007 at 06:58 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Writing an array to a file.
    By Queatrix in forum C++ Programming
    Replies: 8
    Last Post: 04-24-2005, 01:41 PM
  3. writing data to a file from an array of pointers
    By Mingzhi in forum C++ Programming
    Replies: 1
    Last Post: 07-19-2004, 09:07 AM
  4. writing contents of array to file
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 06-26-2002, 04:06 PM
  5. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM