Re: text reading
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 23 Oct 2008 07:37:25 -0700
Keith Thompson <kst@xxxxxxxx> writes:
"Bill Cunningham" <nospam@xxxxxxxxxxxxx> writes:
[...]
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
char line [] = "4.2 4.2";
double price;
double average;
int values_read;
values_read = ssprintf (line, "%lf lf", &price, &average);
if (values_read != 2)
{
fprintf (stderr, "ERROR: badly formed line\n");
exit (EXIT_FAILURE);
}
printf ("price = %f average = %f\n" price, average);
return 0;
}
Why are you wasting your time and ours posting code that you haven't
bothered to compile?
[snip]
I do think that vales_read might need to be a double though.
Why should it be a double? Read the documentation for sscanf. What
type does it return? What does the result mean? Why are you
guessing?
So pat yourself on the back. You've gotten me through a few more pages
in the book of C.
Try again.
It occurs to me (and yes, a lot of people are going to wonder why it
too me so long) that the code you posted could have been written by
someone who is perfectly competent as a C programmer, who then
introduced a few deliberate errors to provoke responses. I note that
you have one syntax error, one misspelling that will result in a link
error, and one fairly subtle typo (I missed it myself on my first
reading) that will cause the program to fail at run time. With those
errors corrected, it's a solid little program; I'd have added "const"
to the declaration of "line", but apart from that I see no problems.
You have just the right #include directives, the formatting is almost
entirely consistent (other than the 4-column vs. 5-column
indentation), the error message is printed to stderr, the program
doesn't try to print the results if sscanf failed, you got the "%lf"
for sscanf vs. "%f" for printf right, you used the value returned by
sscanf correctly.
The charitable interpretation is that you did an uncharacteristically
good job writing the program, and then made some small errors while
re-typing it (rather than copy-and-pasting it as you should have).
My estimate of the likelihood that you are a deliberate troll has just
risen substantially.
Re-reading some of this thread, I see that I've reached an incorrect
conclusion. The code in your article was not yours; it had been
posted by Nick Keighley, who apparently just typed it in without
testing it. (He should have, but IMHO it's a lesser fault in someone
who's offering help than in someone who's asking for it.)
Why did I think that you wrote it? Because it wasn't quoted properly,
so it was impossible to distinguish between your words and Nick's
without going back to read the previous article (which I did only
because of some problems on the machine where I read news). You
(unintentionally) presented Nick's code as your own.
I understand that this problem is caused by a bug in Outlook Express.
You have been told numerous times how to fix the problem, by
installing something called "OE Quotefix". *Please* do so.
And even though the code isn't yours, my advice still stands:
If you're not, then take the program you posted and fix it. Try to
compile and execute it. Fix any errors you see. Repeat until it
works.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: text reading
- From: Nick Keighley
- Re: text reading
- References:
- text reading
- From: Bill Cunningham
- Re: text reading
- From: Nick Keighley
- Re: text reading
- From: Bill Cunningham
- Re: text reading
- From: Nick Keighley
- Re: text reading
- From: Bill Cunningham
- Re: text reading
- From: Keith Thompson
- text reading
- Prev by Date: Re: Preprocessor Directives Management Tool
- Next by Date: Re: rand() % n Revisited
- Previous by thread: Re: text reading
- Next by thread: Re: text reading
- Index(es):
Relevant Pages
|