?
Solved

storing in to a file and reading rom a file

Posted on 2002-06-14
4
Medium Priority
?
169 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 400 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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