[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

storing in to a file and reading rom a file

Posted on 2002-06-14
4
Medium Priority
?
174 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
  • 2
2 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

873 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