Thread: How do i store a file in memory?

  1. #1
    Unregistered
    Guest

    Unhappy How do i store a file in memory?

    ?

  2. #2
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    Well, while I wait for an answer for my question I guess it wouldn't hurt to answer yours.

    First you have to find the length of the file - if you're using stdio.h file functions, fseek to the end of the file, and then use fgetpos. it will return the length of the file. Then, allocate a buffer with malloc that is as long as the file, and fread from the file into the buffer. That's the clumsiest way of doing it, however... but it should give you an idea of where to start. It should also break down the large question you asked into several smaller questions...
    .sect signature

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM