Solved

End of file checking

Posted on 2000-04-16
1
198 Views
Last Modified: 2013-11-20
HI,
 How to check the end of a file condition? I have

void CProj1Doc::Serialize(CArchive& ar)
{
      char str[100];
      if (ar.IsStoring())
      {      
      const CFile* fp = ar.GetFile();
      ar.ReadString(string);
      while (NOT_ENDOF_FILE)
      ar.Read(str,10);
                        
      }
}

Also let me know usage of ReadString instead of Read function.
0
Comment
Question by:mkjoshi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 2720792

I don't understand your code; if you're storing, why are you reading from the archive? That'll just get you a bunch of assertions.

Here's code that works:


void CProj1Doc::Serialize(CArchive& ar)
{
   CString str;
   if (!ar.IsStoring())
   {
      const CFile* fp = ar.GetFile();
      while (ar.ReadString(str))
      {
         // str is a string--you can do something with it
      }
   }
}

and that's that. That code will read the file line-by-line. The loop is controlled by ReadString()--that function itself will return NULL when the file ends, and that will stop your loop.

..B ekiM
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question