Greetings! I am a hardware designer who uses 'C' when needed. Mostly I program for embedded systems but I am trying my hand at Pelles C for use on a windows platform. I am using version 7.00.355 (Win64).
Since most of my work will be console applications, I have been playing with scanf() and printf() formats to understand the pit falls. I have one remaining problem: printf() with a 'long double'. %Le and %Lg work as expected, but %Lf does not. Per the 'fprintf' help reference, it appears it should. "L: Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument."
Below is my test code and output.
// Demonstrate the scanf() with floating point
#include <stdio.h>
int main(void)
{
float f;
double d;
long double ld;
printf("Enter three floating points: ");
scanf("%f %lf %Lf", &f, &d, &ld);
printf(" float %f\n double %f\n long double %Le\n\n", f, d, ld);
printf(" float %f\n double %f\n long double %Lf\n\n", f, d, ld);
printf(" float %f\n double %f\n long double %Lg\n\n", f, d, ld);
return 0;
}
Enter three floating points: 123.456 5328.3495 2.544e-12
float 123.456001
double 5328.349500
long double 2.544000e-12
float 123.456001
double 5328.349500
long double 0.000000
float 123.456001
double 5328.349500
long double 2.544e-12
Press any key to continue...
BTW, isn't it annoying that the formatting rules for scanf() are sometimes different than for printf()? Example: %lf needed for a 'double' in scanf() but %f is needed in printf(). ('l' (ell) does not modify 'f' in a printf(). Can someone share history on this point?
So bottom line question, is the help topic in error or is the printf() in error with regard to '%Lf' or what is the correct format to NOT print in scientific notation for a 'long double'?
Thank you in advance. Source code attached.