sprintf badness

Eychaner, Glenn C. gceych at iago.caltech.edu
Mon Jan 21 10:37:46 AEST 1991


siva at bally.Bally.COM (Siva Chelliah) writes...
>     I am running into problems when I mix floats and integers in sprintf.

No. You are running into problems when you mix floats and doubles in scanf
and sprintf.

>  double k;
   ^^^^^^^^
Note that k is declared as double.

>  sscanf(buf,"%4d%7f%4d",&i,&k,&j);
                  ^^^
I believe this should be "%7lf", for a DOUBLE number.  Same mistake is made
in the next line of the program.

>  printf("i = %d  j = %d  k= %7.2f",i,j,k);
                              ^^^^^
Sorry for posting this.....but it illustrates a BAD HABIT of confusing float
with double (a habit I used to have).

Glenn C. Eychaner | "Do you qualify to be alive, or is the limit of your senses
40386 N. Shore Ln `-----. so as only to survive?" -R.Stevens, _Mr.Businessman_
Big Bear City, CA 92314 `-----------------------. !**** G O  N I N E R S ****!
Eychaner%SunCub.Caltech.edu at Xhmeia.Caltech.edu -|- Big Bear Solar Observatory



More information about the Comp.lang.c mailing list