Solved

storing in to a file and reading rom a file

Posted on 2002-06-14
4
164 Views
Last Modified: 2013-11-20
how to store value of a byte pointer to a file.and after storing how to read from a file and store that value into a byte pointer variable.for ex:
BYTE *p;p is having some value.thatvalue i have to store in to a file.and again i have to read that value from file and store into p .
it's very urgent.
0
Comment
Question by:raju_r
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 7080347
It's not very useful storing a POINTER in a file as the pointer is not likely to be valid when the application is run again and the value is read and used.  But there is nothing stopping you from doing it....

Here's the C way:

FILE *fp;
BYTE *p;

// WRITE the value of p to a file

// Assume that p has some value set....
p = 0x12345678;


fp = fopen("pointerfile.dat", "wb");
if(fp == NULL){
  printf("Error opening file....\n");
  return;
}

// Note that we use the ADDRESS OF p (&p) and not p since
// we want to write the VALUE OF p and NOT the value of
// what p points to.
fwrite((LPVOID)&p, sizeof(BYTE *), 1, fp);

fclose(fp);

// READ the value of p from a file
fp = fopen("pointerfile.dat", "rb");
if(fp == NULL){
  // Whatever....
  return;
}

fread((LPVOID)&p, sizeof(BYTE *), 1, fp);
fclose(fp);
0
 
LVL 32

Expert Comment

by:jhance
ID: 7080348
The MFC way of doing this is pretty much the same using CFile.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 244
maxBlock challenge 30 146
sum13 challenge 24 134
has22 challenge 11 107
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question