Copy data from CPU Buffer to PC hard disk

This is a discussion on Copy data from CPU Buffer to PC hard disk within the C Programming forums, part of the General Programming Boards category; Hi I saved data ( with specific size and address) in main memory of PC (i.e CPU memory)... How can ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Copy data from CPU Buffer to PC hard disk

    Hi

    I saved data ( with specific size and address) in main memory of PC (i.e CPU memory)... How can I copy it in the PC hard dick such as D drive using C programming?

    Thanks
    Hussam

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Open the file with fopen. Write the data to file using fwrite. Close the file with fclose. Be sure to check your return values. Make sense?

  3. #3
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    974
    "hard dick" hahahaah

    Anyway, that sounds pretty easy

    Code:
    FILE f = fopen("mydata.bin","wb");
    char *ptr;
    ptr = 0x12345678; // some address in memory
    fwrite(ptr, sizeofthatdatahere, 1, f);
    fclose(f);
    ptr = NULL;

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Epy View Post
    "hard dick" hahahaah

    Anyway, that sounds pretty easy

    Code:
    FILE f = fopen("mydata.bin","wb");
    char *ptr;
    ptr = 0x12345678; // some address in memory
    fwrite(ptr, sizeofthatdatahere, 1, f);
    fclose(f);
    ptr = NULL;
    1) The result of fopen should be checked.
    2) A conversion from integer to pointer should be explicitly casted.
    3) The result of fwrite should be checked.
    4) Calling fclose on a NULL pointer will likely crash.

  5. #5
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    974
    Yes, this was just a quick example, I was just outlining the process. I would regularly check to see if fopen returns NULL or if the fwrite failed. Points 1 and 4 are basically the same.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. C diamonds and perls :)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  3. Building a pc...water cooling/tons of cooling?
    By Shadow in forum Tech Board
    Replies: 22
    Last Post: 12-20-2002, 04:03 AM
  4. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 05:03 PM
  5. speakers
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 03-31-2002, 07:57 AM

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