Re: Writing to and reading from same file = crash :(

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



See below...
On Tue, 16 Sep 2008 21:10:49 -0700 (PDT), vorange <orangepic@xxxxxxxxx> wrote:

Hi,
I am running 2 modaless windows.
****
That's "modeless", not "modalless". The opposite of "modal" is "modeless"
***
One which is writing to a file
(opened in share mode), the other reading from that file. After
running for a while successfully (about 30 seconds), my program
crashes.
****
"Crash"? What does this word mean? It means nothing. If your program terminates for
some reason, it is almost always accompanied by a message saying what went wrong. It
includes information such as the source line of the program on which this error occurred.
If you enter the debugger, there is a stack backtrace. Lacking any of this information,
it is impossible to tell what is happening.
****

I have a feeling my program is crashing at the part where I'm trying
to read the file.

Basically I am reading line by line from the file, tokenizing each
line (by its tab) and putting each item (3 numbers separated by tab)
into a CArray. Do you see anything wrong with what's below? :

while(src.ReadString(strLine)
{
while(AfxExtractSubString(resToken, strLine, s, _T(' ')))
****
It looks like you are looking for two spaces. If you are looking for a tab, it would be
_T('\t'). It is considered poor practice to put literal tab characters in quoted strings
(my editor, for example, replaces all tabs with spaces, always, because I do not believe
in tab characters in source files).
*****
{
_stscanf( resToken, _T("%f %lf"), &floatnum, &doublenum );
****
_stscanf is considered one of the several incredibly hazardous library calls. There is
always the possibility that you are overwriting data when you use it. I do not use ANY of
the scanf family of functions because they are essentially kludges of the worst sort. When
they work, everything is fine, but if they fail, they fail silently and simply produce
incorrect results. I would start by replacing this line with something robust, reliable,
and guaranteed not to overwrite memory. Of course, since nothing you have said in this
post actually gives the SLIGHTEST idea of what went wrong, it is hard to tell, but any
line which includes a scanf-class operation is intrinsically offensive and must be
rewritten.
****

// some logic to put each tokenized items into CArray
}
}

The compiler flags a line from some windows file when it crashed. The
line where it says IAtlStringMgr...etc. Is it related to my code
above or is this telling me the problem is somewhere else?
****
Which line? Where was it called from your program? What was your program doing?

It is probably related to your code, but since you provided no information other than the
totally meaningless word "crash" there is no way to tell what could possibly have gone
wrong.
joe
****

void Empty() throw()
{
CStringData* pOldData = GetData();
IAtlStringMgr* pStringMgr = pOldData->pStringMgr;
if( pOldData->nDataLength == 0 )
{
return;
}


Thank you
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Writing to and reading from same file = crash :(
    ... I am running 2 modaless windows. ... Basically I am reading line by line from the file, ... line (by its tab) and putting each item ... // some logic to put each tokenized items into CArray ...
    (microsoft.public.vc.mfc)
  • Re: Singers and Musicians?
    ... Sight reading is what you do when you sit ... most-accomplished tab reader in the world, and set him down in front ... I've written in numerous posts. ...
    (alt.guitar.bass)
  • Re: XP? I think not!
    ... Processes tab, but it doesn't appear in the Application tab. ... and I was just reading the following quote: ... Great reading. ... >> Microsoft is furiously becoming what IBM once was -- irrelevent. ...
    (microsoft.public.vb.general.discussion)
  • Re: question about teaching and learning guitar
    ... It's not like reading music is anything difficult. ... in expressing rhythmic figures in tab. ... to really dig to find ways to practice reading notation...that is why it ... playing my instrument and making music. ...
    (alt.guitar.beginner)
  • Re: Suggestions for Music Stand
    ... I should get in order to play standing nice and ... upright while reading some sheet music or even tab ...
    (alt.guitar.beginner)