|
struct st_Test
{
int nTestSize;
double DateTime;
char strIP[20];
char strPORT[10];
st_Test()
{
nTestSize= 0;
DateTime = 0;
memset(this, 0, sizeof(st_Test));
}
};
구조체고요
TFileStream *pSendHeaderData = new TFileStream(Edit1->Text, fmOpenWrite|fmShareExclusive);
st_Test stTest;
stTest.nTestSize = AData.Length;
stTest.DateTime = now.Val;
memcpy(&stTest.strIP[0], strIP.c_str(), strIP.Length());
memcpy(&stTest.strPORT[0], strPORT.c_str(), strPORT.Length());
pSendHeaderData->Seek(0, soFromEnd);
pSendHeaderData->Write(&stTest, sizeof(st_Test));
pSendHeaderData->Write(&AData, AData.Length);
delete pSendHeaderData;
파일에 저장하고요.
TFileStream *pFileStream = new TFileStream(OpenDialog1->FileName, fmOpenRead);
st_Test stTest;
pFileStream->Position = 0;
while(pFileStream->Position < pFileStream->Size)
{
TDateTime now;
AnsiString strIP;
AnsiString strPORT;
char *psTempIP = new char(20);
char *psTempPORT = new char(10);
pFileStream->Read(stTest , sizeof(st_Test ));
memcpy(psTempIP, &pstFileData.strIP[0], sizeof(st_Test));
memcpy(psTempPORT, &pstFileData.strPORT[0], sizeof(st_Test));
strIP = psTempIP;
strPORT = psTempPORT;
delete psTempIP;
delete psTempPORT:
TBytes ReadBytes;
ReadBytes.Length = stTest ->nTestSize ; // 처음엔 25값이 잘 들어가다가 파일리드로 내려가면
쓰레기값이 들어가네요
pFileStream->Read(&ReadBytes, ReadBytes.Length); //리드 하면 쓰레기 값으로 변경 ㅠㅠ
now.Val = stTest ->DateTime; //여기 값이 잘 들어옴
PrintReceveList(now, strIP, strPORT, ReadBytes); //여기오면 값이 변경되어 있음
}
delete pFileStream;
테스트 사이즈값을 넘겼는데 왜 리드바이트랭스에 쓰레기가 들어갈까요??
왜 출력 함수에서 넘길라고 하면 값이 변경되어 있을까요??????? ㅠㅠ
|