Re: [C] erroneous fprintf output
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 05/11/04
- Next message: Francis Glassborow: "Re: [C] erroneous fprintf output"
- Previous message: Curley Q.: "Re: [C] erroneous fprintf output"
- In reply to: Curley Q.: "Re: [C] erroneous fprintf output"
- Next in thread: Francis Glassborow: "Re: [C] erroneous fprintf output"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 10 May 2004 19:44:17 -0400 (EDT)
On Mon, 10 May 2004, Curley Q. wrote:
>
> Pedro Graca wrote:
> > Your previous printf() call correctly uses %f.
> > I suggest you remove the "l"s from the specifiers in fprintf().
> >
> >
> > fprintf(output, "sum1: %.2f sum2: %.2f\n", sum1, sum2);
>
> I believe %lf is the correct double format specifier for fprintf.
You believe incorrectly. %lf *is* the correct format specifier
for *scanf, but not *printf --- because whereas there is a significant
difference between (float*) and (double*), any values of type (float)
get implicitly converted to values of type (double) when passed to
variadic functions such as *printf. Since there is no way for
*printf to receive a value of type (float), it makes sense that there
be no corresponding format specifier.
> If this were the problem why would one of the %lf formatted
> values be printed correctly and not the other?
Does it matter?
-Arthur
- Next message: Francis Glassborow: "Re: [C] erroneous fprintf output"
- Previous message: Curley Q.: "Re: [C] erroneous fprintf output"
- In reply to: Curley Q.: "Re: [C] erroneous fprintf output"
- Next in thread: Francis Glassborow: "Re: [C] erroneous fprintf output"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|