strange issue with reading files...

rory rorywalsh at gmail.com
Fri Jan 4 11:15:48 PST 2008


On Jan 4, 8:48 pm, rwa... at gmail.com ("Robert Anderson") wrote:
> On Jan 4, 2008 10:30 AM, rory <rorywa... at gmail.com> wrote:
>
>
>
>
>
> > On Jan 4, 8:16 pm, rwa... at gmail.com ("Robert Anderson") wrote:
> > > On Jan 4, 2008 9:53 AM, rory <rorywa... at gmail.com> wrote:
>
> > > > On Jan 4, 7:14 pm, w... at 61131.com wrote:
> > > > > Moin Rory,
>
> > > > > did You open the file in binary mode? The default is text mode which
> > > > could result in wrong positioning.
>
> > > > > Hope this helps
> > > > > Friedrich
>
> > > > > ----- Original Message -----
> > > > > From: "rory" <rorywa... at gmail.com>
>
> > > > > Newsgroups: comp.soft-sys.wxwindows
> > > > > To: <wx-us... at lists.wxwidgets.org>
> > > > > Sent: Friday, January 04, 2008 5:54 PM
> > > > > Subject: strange issue with reading files...
>
> > > > > > I've spent to whole day trying to figure out how do the following
> > in a
> > > > > > wxwidget application:
> > > > > > 1) open a binary file, an .exe to be precise,
> > > > > > 2) read the last 10 chars from the end
> > > > > > 3) offset the file by the value contained in those last 10 chars
> > > > > > 4) retrieve everything from there till the end of the file.
>
> > > > > > I have it working without any problem in a non wxWidgets program
> > but
> > > > > > as soon as I try to do it from my wx app it doesn't work. This is
> > the
> > > > > > code I'm using:
>
> > > > > >  std::string str, csdText;
> > > > > >  char buf[10];
> > > > > >  fstream inFile( appName.c_str());
> > > > > >  if(!inFile)  cerr << "Error";
> > > > > >  inFile.seekg(-10, ios::end);
> > > > > >  inFile.get(buf, sizeof(char)*10);
> > > > > >  int pos = atoi(buf)+10;
>
> > > > > >  wxMessageBox(buf);
> > > > > >  inFile.seekg(-pos, ios::end);
>
> > > > > >  csdText = "";
> > > > > >  while(!inFile.eof()){
> > > > > >        getline(inFile, str);
> > > > > >        csdText = csdText+str;
> > > > > >    }
>
> > > > > >   wxMessageBox(csdText.c_str());
>
> > > > > > I've also tried with wxFile but I didn't have any joy with that
> > > > > > either. As a last resort I tried a straightforward C
> > implementation
> > > > > > but that also fails with odd results. Can anyone see what the
> > problem
> > > > > > might be, hopefully it is something silly I am overlooking. Please
> > let
> > > > > > me know if you need any further info. I'm using wxWidgets 2.8.
> > Cheers,
>
> > > > > > Rory.
>
> > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> > > > > > For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org
>
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> > > > > For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org
>
> > > > Ok, I'm now successfully opening the file using an ifstream in
> > > > ios::binary mode. Now the program does not hang but I still get
> > > > rubbish in my display boxes. When I check the same input file with
> > > > another non-gui application it displays the end of the file without
> > > > any problems so I know there are characters at the end of the binary
> > > > file. Any other ideas?
>
> > > Set aside wx for now and write a small program to read your file and
> > display
> > > your desired results with cout.  When you get that working, and still
> > have
> > > difficulties with the wx implementation, then it will be appropriate to
> > ask
> > > questions about how to accomplish things in wx.
>
> > > Bob
>
> > Thanks Robert but that is what I did from the start. I have a simple c+
> > + prog that does exactly what I want. When I insert that code into a
> > function in my wx application it doesn't work, hence my frustration.
> > Replacing the wxMessageBox's above with cout's will work for me if I
> > build a simple it as a simple command line application.
>
> > Rory.
>
> Did you compare the contents of buf and the value of pos in your reference
> (command line) implementation with your wx implementation?  Are they
> identical?
>
> Bob

pos seems to be the same but the contents of buf are not, in fact it
looks like buf is returning NULL. I am going to have to leave it for
the night, I will try again tomorrow and double check to see if buf is
returning NULL. I would check now but I'm at a diferent PC, thanks
again for the help.

Rory.






More information about the wx-users mailing list