How do i store a file in memory?

This is a discussion on How do i store a file in memory? within the C Programming forums, part of the General Programming Boards category; ?...

  1. #1
    Unregistered
    Guest

    Unhappy How do i store a file in memory?

    ?

  2. #2
    ggs
    ggs is offline
    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, 08:51 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07: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, 11:51 PM

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