Solved

Writing Byte Pointer to File

Posted on 2002-07-23
6
189 Views
Last Modified: 2013-11-20
Hi,

I want to write
byte *a;
to a file. how can i write ?
 
0
Comment
Question by:dhirajbhise
6 Comments
 
LVL 1

Accepted Solution

by:
jemax earned 50 total points
ID: 7173659
Hi,

ptr itself
 WriteFile (f, (LPCVOID)a, sizeof(LPVOID),...)
value at *a
 WriteFile (f, (LPCVOID)*a, sizeof(BYTE),...)

HTH,
jemax
0
 
LVL 1

Expert Comment

by:ackava
ID: 7174030
/*
    The following code is to write byte * b into file
    NOTE : nSize is size of bytes pointed by *b
*/

int nSize = ...;

FILE * fp = fopen("yourfilename.ext","wb");
if(fp==NULL)
{
    // OOPS SOME ERROR
}
else
{
    fwrite(&nSize,4,1,fp);
    fwrite(b,nSize,1,fp);
    fclose(fp);
}


/*
    The following code is to read same thing from file
*/
int nSize = ...;

FILE * fp = fopen("yourfilename.ext","wb");
if(fp==NULL)
{
    // OOPS SOME ERROR
}
else
{
    fread(&nSize,4,1,fp);
    b = new byte [nSize];
    fread(b,nSize,1,fp);
    fclose(fp);

    // now you can use byte * b
}
0
 
LVL 1

Expert Comment

by:ackava
ID: 7174032
Sorry a minor bug in my previous post, use this.

/*
   The following code is to write byte * b into file
   NOTE : nSize is size of bytes pointed by *b
*/

int nSize = ...;

FILE * fp = fopen("yourfilename.ext","wb");
if(fp==NULL)
{
   // OOPS SOME ERROR
}
else
{
   fwrite(&nSize,4,1,fp);
   fwrite(b,nSize,1,fp);
   fclose(fp);
}


/*
   The following code is to read same thing from file
*/
int nSize = ...;

FILE * fp = fopen("yourfilename.ext","rb");
if(fp==NULL)
{
   // OOPS SOME ERROR
}
else
{
   fread(&nSize,4,1,fp);
   b = new byte [nSize];
   fread(b,nSize,1,fp);
   fclose(fp);

   // now you can use byte * b
}
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 8

Expert Comment

by:fl0yd
ID: 7174401
A short note: Why are you writing a POINTER to a file? Unless you are using this for diagnostics it carries very little information. The next time you run your application, this pointer is completely worthless since it most definately changed. If you are using MSVC and run your application in debug mode it will be the same to make debugging easier; in release build, however, it will point to a different location in memory.
0
 
LVL 1

Expert Comment

by:kender_a
ID: 7176613
fl0yd,

Is the feature of the MSVC debug mode documented, or it's only and observation? (I observed this myself.)

Thanks,
Kender
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7177395
I read it somewhere -- don't remember where, though. I think it was some official ms paper, but don't hold me responsible for it ;)
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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 98
while loop over for loop 7 103
only14 challenge 19 76
matchUp  challenge 6 63
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

777 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