I
ishmael4
hello everyone!
i have a problem with reading from binary file. i was googling and
searching, but i just cant understand, why isnt this code working. i could
use any help. here's the source code:
--cut here--
typedef struct pkg_ {
short int info;
char* data[5000];
} pkg;
TFileStream* File;
void SendFile(char* FName, int status)
{
File=new TFileStream(FName,fmOpenRead);
while(File->Position<File->Size)
{
char *block[5000];
pkg* newPkg=new pkg;
File->Read(block,5000);
memcpy(*(newPkg->data),*(block),5000); //this line
newPkg->info=0;
Form1->SS1->Socket->Connections[0]->SendBuf((void*)newPkg,sizeof(newPkg));
delete newPkg;
}
pkg* newPkg=new pkg;
newPkg->info=status;
Form1->SS1->Socket->Connections[0]->SendBuf((void*)newPkg,sizeof(newPkg));
delete newPkg;
delete File;
return;
}
--cut here--
i was trying
memcpy(*(newPkg->data),*(block),5000); //this line
and getting "access violation" message, as well as
memcpy(newPkg->data,block,5000); //this line
but in this case "newPkg->data" appears to be a simple pointer, not an array
of pointers, as "block". And during debugging the following information
about contents of these variables are shown:
newPkg->data:=0090568C
block={:57200A0D, :6D756C6F, etc. etc. (the actual content of a binary
file)}
juest after instruction "memcpy(newPkg->data,block,5000); //this line".
Please help me.
i have a problem with reading from binary file. i was googling and
searching, but i just cant understand, why isnt this code working. i could
use any help. here's the source code:
--cut here--
typedef struct pkg_ {
short int info;
char* data[5000];
} pkg;
TFileStream* File;
void SendFile(char* FName, int status)
{
File=new TFileStream(FName,fmOpenRead);
while(File->Position<File->Size)
{
char *block[5000];
pkg* newPkg=new pkg;
File->Read(block,5000);
memcpy(*(newPkg->data),*(block),5000); //this line
newPkg->info=0;
Form1->SS1->Socket->Connections[0]->SendBuf((void*)newPkg,sizeof(newPkg));
delete newPkg;
}
pkg* newPkg=new pkg;
newPkg->info=status;
Form1->SS1->Socket->Connections[0]->SendBuf((void*)newPkg,sizeof(newPkg));
delete newPkg;
delete File;
return;
}
--cut here--
i was trying
memcpy(*(newPkg->data),*(block),5000); //this line
and getting "access violation" message, as well as
memcpy(newPkg->data,block,5000); //this line
but in this case "newPkg->data" appears to be a simple pointer, not an array
of pointers, as "block". And during debugging the following information
about contents of these variables are shown:
newPkg->data:=0090568C
block={:57200A0D, :6D756C6F, etc. etc. (the actual content of a binary
file)}
juest after instruction "memcpy(newPkg->data,block,5000); //this line".
Please help me.