LuckyLucks
asked on
writing from a pointer to a file
Hi
I am trying to write a certain number of bytes, pointed by a pointer, p, to a file called myfile.
int numbytes=sizeof(float)*56;
FILE *myfile;
myfile=fopen("out.txt","w" ); //returns a <Bad Ptr>
memcpy(myfile,memoryPtr,nu mbytes);
I noticed that myfile has a value 0x57251448 but it also says <Bad Ptr>. However, i read some confusing remarks on the web saying that might not necessarily mean something bad i,e <Bad Ptr> might just mean NULL pointer.
However, when i proceed with that in mind and I do memcpy, Visual Studio crashes and I am sent to some dbgheap.c file where I get an error at
/* check if the heap was not allocated by _aligned routines */
if ( nBlockUse == _NORMAL_BLOCK)
{
if ( CheckBytes((unsigned char*)((uintptr_t)pUserDat a & ~(sizeof(uintptr_t) -1)) -nAlignGapSize,_bAlignLand Fill, nAlignGapSize))
{
// We don't know (yet) where (file, linenum) pUserData was allocated
_RPT1(_CRT_ERROR, "The Block at 0x%p was allocated by aligned routines, use _aligned_free()", pUserData);
errno = EINVAL;
return;
}
What's the best way to write a chunk of memory , pointed to by a pointer, to a file? And what is wrong with the current way I am doing things?
I am trying to write a certain number of bytes, pointed by a pointer, p, to a file called myfile.
int numbytes=sizeof(float)*56;
FILE *myfile;
myfile=fopen("out.txt","w"
memcpy(myfile,memoryPtr,nu
I noticed that myfile has a value 0x57251448 but it also says <Bad Ptr>. However, i read some confusing remarks on the web saying that might not necessarily mean something bad i,e <Bad Ptr> might just mean NULL pointer.
However, when i proceed with that in mind and I do memcpy, Visual Studio crashes and I am sent to some dbgheap.c file where I get an error at
/* check if the heap was not allocated by _aligned routines */
if ( nBlockUse == _NORMAL_BLOCK)
{
if ( CheckBytes((unsigned char*)((uintptr_t)pUserDat
{
// We don't know (yet) where (file, linenum) pUserData was allocated
_RPT1(_CRT_ERROR, "The Block at 0x%p was allocated by aligned routines, use _aligned_free()", pUserData);
errno = EINVAL;
return;
}
What's the best way to write a chunk of memory , pointed to by a pointer, to a file? And what is wrong with the current way I am doing things?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.