Solved

storing in to a file and reading rom a file

Posted on 2002-06-14
4
163 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 105
Excel Use VBA to get user's Mac Address for their computer 5 241
sumDigits challenge 9 170
NotAlone Challenge 20 84
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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