P
PeterOut
If you keep posting to irrelevant groups, no one will want to help
you.
The problem is that I am not sure if it a problem with my C code or a
problem with MS Visual C++.
If you keep posting to irrelevant groups, no one will want to help
you.
PeterOut said:The problem is that I am not sure if it a problem with my C code
or a problem with MS Visual C++.
The problem is that I am not sure if it a problem with my C code or a
problem with MS Visual C++.
Hmmm, I was thinking that it might be a consequence of corrupt memory
(like buffer overruns, changing memory after free() (or equivalent) or
some other similar problem).
Test if you have access to a function called AfxCheckMemory(). (It is
available in later versions of their compiler, don't know if it is in
that version however).
If it is available try placing
ASSERT(AfxCheckMemory());
immediately before the call to fscanf(). If it breaks you have
previously overwritten some memory somewhere in your program where that
should not happen...- Hide quoted text -
- Show quoted text -
char csBuffer[32];iRows-1;
Of what?Look at line 42.
Hi Johan,
That looks likfe a handy function. Thanks for bringing it to my
attention. I put it in and it didn't flag anything. I have decided
to give up on fscanf and add the following code instead.
ERROR_NUMBER FReadLine(FILE *fpInputFile, char *csBuffer)
{
int i;
if ((csBuffer[0] = fgetc( fpInputFile )) == EOF) return
ERROR_READING_FILE;
i = (csBuffer[0] == '\n')? 0 : 1;
while ((csBuffer = fgetc( fpInputFile )) != '\n')
{
if (csBuffer[i++] == EOF) return ERROR_READING_FILE;
}
csBuffer = '\0';
return ERROR_NONE;
}
if ((fpFile = fopen(csFileName, "r")) == NULL)
{
// Error handling
}
{
float fMean;
long lX, lY, lLastX = fppPlane->iColumns-1, lLastY = fppPlane-char csBuffer[32];iRows-1;
do
{
if ((enErrorNumber=FReadLine(fpFile, csBuffer))!=ERROR_NONE) break;
lX=atoi(strtok(csBuffer, "\t"));
lY=atoi(strtok(NULL, "\t"));
fMean=(float)atof(strtok(NULL, "\t"));
} while (lX < lLastX || lY < lLastY);
}
fclose(fpFile);
So far no problem.
Thanks again for your help,
Peter.
Of what?
MUCH more than worth it. I have replaced a black box that hangs withThis sure seems like a lot of work just avoid calling fgets.
Excellent point. I will modify FReadLine() so that there is a maximumIs 32 bytes really sufficient to hold the longest line in your file?
The cast is superfluous.
So you have managed to camouflage the problem with no understanding of
what the real issue was?
fMean=atof(strtok(NULL, "\t"));
warning C4244: '=' : conversion from 'double' to 'float', possible
loss of data
MUCH more than worth it. I have replaced a black box that hangs with
much more transparent code that does not. ...
I may have evaded the issue but have replaced a black box, that hangs
with no error message, with more transparent code. fscanf probably
hung because it was waiting for a particular input. It was not
suitable for this application since the expected input may not have
been in the input file.
[...] many people seem not to realize that Standard C
provides for exactly two separate kinds of failure: "failure due
to ordinary end of file", for which feof() will say "yes" and
ferror() will say "no",
....sure.
and "failure due to bad floppy disk, or
cpu catching fire, or any other not-ordinary-EOF-disaster", for
which feof() will say "no" and ferror() will say "yes".]
... That is, does the Standard guarantee that (feof(fp) && ferror(fp))
evaluates to 0?
Is there not scope for some condition in which, say, 32
bytes were requested, there were only 30 bytes left on the file, so EOF
would certainly be encountered, and only 16 bytes could be read because
the next bit of the file was in a bad sector, so that both Bad Things
are happening at once?
PeterOut said:
The diagnostic message, whilst not compulsory, is useful, in that it
tells you that the conversion may not be able to retain all the
precision that would be available to you were you to use double.
Suppressing the diagnostic information is like taking the battery out of
your doorbell. There's still someone at the door, even if you can't
hear them any more.
Frankly, I'd use double. (And while I was at it, I'd use strtod instead
of atof and strtol instead of atoi.)
I certainly wouldn't pass strtok(NULL, "\t") to anything expecting a
string as an argument, in case the string you're parsing turned out to
be poorly formed.
I think Barry Schwarz's point was that you could just call fgets()
(*not* fscanf()!), instead of using another 15 or so lines of code
to re-implement fgets().
Richard Heathfield said:Suppressing the diagnostic information is like taking the battery out of
your doorbell.
Ben said:Doorbells are battery-powered in England? Yet another way that
it's such a foreign country...
Doorbells are battery-powered in England?
> Yet another way that
it's such a foreign country...
I've found that doubles tend to increase the processing time relative
to singles and the data I work with (biological) does not have that
level of accuracy.
I have been looking into using strchr instead but it appears that my
problem is a deadlock. Multithreading was the default for the
development platform I am using (MS Visual C++ 6.0) but I am not
really an expert in multithreaded programming Maybe I should stick to
single threaded until I know what I want to do with multithreaded.
Doorbells are battery-powered in England?
Yet another way that it's such a foreign country...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.