CArchive load gives null lines
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CArchive load gives null lines

  1. #1
    Join Date
    Jul 2013
    Posts
    9

    CArchive load gives null lines

    Hello all,

    I am trying to reuse some code from my Visual C++ 2005. I am using CArchive to ReadString the first line of a file into another string. However, I am seeing squares where there should be spaces when I view it in the debugger. Can anyone explain what’s going on here?

    Here's the code:
    Code:
    if( cfSAP.GetStatus(csRegExtractFileRemote, cfsStatus))
       {
    	 if( !cfSAP.Open( csRegExtractFileRemote, CFile::modeRead, &ef ) )
    	  {
    			  cout<<"FAILED\n"<<endl;
    			  ef.ReportError();
      		              return FALSE;
    	  }
    	  cout<<"SUCCESS\n"<<endl;
    
    	  CArchive caSAP( &cfSAP, CArchive::load );
    	  CString csNewLine;
                   int iTotalLines = 0;
    	   
    	while(1)
    	{
            iTotalLines++;
            //
            // Read next line from file.
            //
    		BOOL bVal1 = FALSE;
    		bVal1 = caSAP.ReadString(csNewLine);
            if ( bVal1 == FALSE ) break;
    		printf("CurrentLine : %S ",csNewLine);
    I am able to see some junk characters like this
    ㌳㐵‵†††䡓䙁⁔††䅍乔䵕䕂ㅒ਍㈰㐳㘵㔴㔶ㅃ㌵䌭㌭㤴㜵‸†††剂䍁䕋⁔†䅍乔䵕䕂㉒"
    in csRegExtractFileRemote and also in the bool variable bval1

    I am not able to read the lines due ti this bug ,

    can any one help me in this

    NOTE:This is normal text file contains two lines of information like this
    0234568374C186-M-233545 SHAFT MATNUMBER1
    0234564565C153-C-349578 BRACKET MATNUMBER2
    Last edited by nini18110; August 1st, 2013 at 07:33 AM. Reason: providing more info

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: CArchive load gives null lines

    Quote Originally Posted by nini18110 View Post
    Hello all,

    I am trying to reuse some code from my Visual C++ 2005. I am using CArchive to ReadString the first line of a file into another string. However, I am seeing squares where there should be spaces when I view it in the debugger. Can anyone explain what’s going on here?

    Here's the code:
    Code:
    if( cfSAP.GetStatus(csRegExtractFileRemote, cfsStatus))
       {
    	 if( !cfSAP.Open( csRegExtractFileRemote, CFile::modeRead, &ef ) )
    	  {
    			  cout<<"FAILED\n"<<endl;
    			  ef.ReportError();
      		              return FALSE;
    	  }
    	  cout<<"SUCCESS\n"<<endl;
    
    	  CArchive caSAP( &cfSAP, CArchive::load );
    	  CString csNewLine;
                   int iTotalLines = 0;
    	   
    	while(1)
    	{
            iTotalLines++;
            //
            // Read next line from file.
            //
    		BOOL bVal1 = FALSE;
    		bVal1 = caSAP.ReadString(csNewLine);
            if ( bVal1 == FALSE ) break;
    		printf("CurrentLine : %S ",csNewLine);
    I am able to see some junk characters like this
    ㌳㐵‵†††䡓䙁⁔††䅍乔䵕䕂ㅒ਍㈰㐳㘵㔴㔶ㅃ㌵䌭㌭㤴㜵‸†††剂䍁䕋⁔†䅍乔䵕䕂㉒"
    in csRegExtractFileRemote and also in the bool variable bval1

    I am not able to read the lines due ti this bug ,

    can any one help me in this

    NOTE:This is normal text file contains two lines of information like this
    0234568374C186-M-233545 SHAFT MATNUMBER1
    0234564565C153-C-349578 BRACKET MATNUMBER2
    Why are you trying to use a CArchive as if it were a file? That's not what they do or how they work. If you just want to read a text file, use CStdioFile.

    Also, it's not necessary to check for existence for a file. If it's not there, your Open will fail and the File Exception will report that.

  3. #3
    Join Date
    Jul 2013
    Posts
    9

    Re: CArchive load gives null lines

    Thanks for thre Reply ,

    Since file existance would change for every hour i have to check for the file existance every time whenever i am running the application,
    It is an existing requirement to make use of CArchive ,can tell me is there any way to find out the error why it is giving me NULL lines even though there a data in my text file

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,277

    Re: CArchive load gives null lines

    I am able to see some junk characters like this
    ㌳㐵‵†††䡓䙁⁔††䅍乔䵕䕂ㅒ਍㈰㐳㘵㔴㔶ㅃ㌵䌭㌭㤴㜵‸†††剂䍁䕋⁔†䅍乔䵕䕂㉒"
    in csRegExtractFileRemote and also in the bool variable bval1
    If you are seeing junk characters in BOOL variable bval1 then something is very wrong indeed as a type BOOL variable holds a number (usually 0 or 1 but can be any integer). How are you 'seeing' junk characters in bval1?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: CArchive load gives null lines

    Quote Originally Posted by nini18110 View Post
    Thanks for thre Reply ,

    Since file existance would change for every hour i have to check for the file existance every time whenever i am running the application,
    It is an existing requirement to make use of CArchive ,can tell me is there any way to find out the error why it is giving me NULL lines even though there a data in my text file
    Again, that's not what CArchive does, so if it's a requirement, it's either a stupid one, or you're not understanding it. CArchive serializes objects in a binary format so that object states and relationships can be stored to disk and restored. It's not for reading text files. Whatever you read into a CArchive should have been saved out using one also.

    "CArchive Allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted. "
    http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx
    Last edited by GCDEF; August 1st, 2013 at 08:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center