File reading: In which addresses is a file stored?

This is a discussion on File reading: In which addresses is a file stored? within the C Programming forums, part of the General Programming Boards category; Hi! Let's say that we have a program, written in C, which reads a file (in my case is a ...

  1. #1
    Registered User paok's Avatar
    Join Date
    Nov 2007
    Posts
    8

    File reading: In which addresses is a file stored?

    Hi! Let's say that we have a program, written in C, which reads a file (in my case is a bitmap file). It's storing the file in some address space, right? Is there any way to find out in which addresses is the file stored? or can I give the starting address where the file is going to be stored?

    ps: sorry for my english

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    Quote Originally Posted by paok View Post
    Hi! Let's say that we have a program, written in C, which reads a file (in my case is a bitmap file). It's storing the file in some address space, right? Is there any way to find out in which addresses is the file stored? or can I give the starting address where the file is going to be stored?

    ps: sorry for my english
    You have to allocate the buffer big enough to hold all the file (if you want to read the whole file at once)

    you can allocate memory with malloc, which will return a starting address of the buffer

    Then you will give this address to fread to read the contents of the file into the buffer
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Files are stored on the hard-disk. Portions of the file is then copied into memory when you read the file. But the file as such hasn't got an address.

    There are functions in most OS's that allow you to MAKE the file appear like it's part of memory, such as MapViewOfFile() in Windows and mmap() in Linux. But that's essentially just hiding the fact that the file is a set of sectors on the hard-disk, and "moving" the task of actually reading the file into the memory management process, but it's still having to be read and written into memory.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by paok View Post
    Hi! Let's say that we have a program, written in C, which reads a file (in my case is a bitmap file). It's storing the file in some address space, right? Is there any way to find out in which addresses is the file stored? or can I give the starting address where the file is going to be stored?
    When you load data into memory, you have to give an address (i.e. a pointer). Naturally, this address is where the data will be located...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. A doubt about how data is stored in a file
    By avi2886 in forum C Programming
    Replies: 7
    Last Post: 04-16-2009, 02:37 AM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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