fscanf hangs

P

PeterOut

If you have measured and found that for your work this is the case, then
it is a valid reason for using float rather than double. Just remember
that this is not the case for all hardware or all programs on some
specific pieces of hardware. Also remember that double normally supports
a larger range than float, not just greater precision.

That's good to know. Thanks. However, the range offered by single
precision floats is more than adequate for my current application.
Also, I am looking to make the program transferable across a range of
hardware and operating systems.
The comment about strtol instead of atoi is still valid, because that is
about the ability to detect and handle input errors.


If using multithreading, or you might go back to it in the future, then
that is an even bigger reason not to use strtok. However, yes,
multithreading does give you a number of additional headaches such as
deadlock if you are not experienced (or even if you are) so you should
only use threads if you have a real reason to do so.

Yes. Thank you for your help. And thank you to everyone for their
help with this problem. I have combined advice and now have the
following code.

ASSERT(AfxCheckMemory());
{
float fMean;
int lX, lY, lLastX = fppPlane->iColumns-1, lLastY = fppPlane-
char csBuffer[32], * pEnd;

do
{
if (!fgets(csBuffer, 32, fpFile)) break;
lX=strtol( csBuffer, &pEnd, 10 );
lY=strtol( pEnd, &pEnd, 10 );
fMean=(float)strtod( pEnd, &pEnd );
fppPlane->Data[lY][lX] = fMean;
} while (lX < lLastX || lY < lLastY);
}
Threads are off topic here. There is I believe a group specifically for
threads, and there are lots of platform specific groups.

I see your point. I have found now a newsgroup about threads.
However, when I started this thread I wist not whence cameth the
source of the hang. I had never heard of deadlocks and knew very
little about multithreading. That problem became more apparent after
I had started the thread.

Thanks,
Peter.
 
B

Barry Schwarz

That's good to know. Thanks. However, the range offered by single
precision floats is more than adequate for my current application.
Also, I am looking to make the program transferable across a range of
hardware and operating systems.

Both double and float are standard types so that does not affect your
choice. While floats reduce processing time on your system
(hardware+OS+compiler+run time library), they may have the opposite
affect on a different one. Using the results of your measurements is
obviously better than guessing but still may not have the desired
effect once you port the code.
Yes. Thank you for your help. And thank you to everyone for their
help with this problem. I have combined advice and now have the
following code.

ASSERT(AfxCheckMemory());

What is ASSERT? It is not the standard assert macro because C is case
sensitive.

What is this block supposed to represent? It doesn't seem related to
the previous discussion of threads.
float fMean;
int lX, lY, lLastX = fppPlane->iColumns-1, lLastY = fppPlane-
char csBuffer[32], * pEnd;

do
{
if (!fgets(csBuffer, 32, fpFile)) break;
lX=strtol( csBuffer, &pEnd, 10 );

A little horizontal white space in your code would make it a lot more
readable.
lY=strtol( pEnd, &pEnd, 10 );
fMean=(float)strtod( pEnd, &pEnd );

I find it strange that you need to cast this to suppress the warning
about implicitly converting double to float but don't need a cast when
converting a long to an int. Maybe on your system sizeof(long) ==
sizeof(int).
fppPlane->Data[lY][lX] = fMean;

You don't do any error checking on your calls to the strto* functions.
You don't do any range checking on lX or lY. I wonder if there is a
standard term for (excessive) faith in the correctness of input.
} while (lX < lLastX || lY < lLastY);
}


Remove del for email
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top