Solved

Writing Byte Pointer to File

Posted on 2002-07-23
6
187 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 66
java ^ examples 8 57
canBalance challenge 34 65
Annoying "thing" blocks my view 4 50
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

12 Experts available now in Live!

Get 1:1 Help Now