Solved

storing in to a file and reading rom a file

Posted on 2002-06-14
4
155 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
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
Comment Utility
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
Comment Utility
The MFC way of doing this is pretty much the same using CFile.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 109
Expand to include initial dialog with two choices. 9 59
only14 challenge 19 63
mapBully challenge 6 88
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now