C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[67283] TFileStream 좀 봐주세요
축구 [] 1113 읽음    2012-05-22 13:47
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;


테스트 사이즈값을 넘겼는데 왜 리드바이트랭스에 쓰레기가 들어갈까요??

왜 출력 함수에서 넘길라고 하면 값이 변경되어 있을까요???????  ㅠㅠ

+ -

관련 글 리스트
67283 TFileStream 좀 봐주세요 축구 1113 2012/05/22
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.