scanf doesn't work for variables of type double

Richard O'Keefe ok at cs.mu.oz.au
Sat Sep 16 16:15:21 AEST 1989


In article <12988 at uhnix1.uh.edu>, jsmng at csune.cs.uh.edu writes:
>[having trouble with scanf("%f", &double_var)]
> Does anyone have any experience with this? According to K&R, %f for
> double should be allowed in scanf. We are running SunOS 4.0.1 and
> I think our C compiler follows the K&R standards (as opposed to ANSI).

K&R 1st edition section 7.4 page 149:
	f	a floating-point number is expected; the corresponding
		argument should be a pointer to a FLOAT.  ...
	the conversion characters e or f may be preceded by l to
	indicate that a pointer to DOUBLE rather than a pointer to
	FLOAT is in the argument list.

Ever since K&R1 it has been the case that %e and %f in scanf() required
pointer-to-float in the argument list, while if the argument list had
pointer-to-double the format had to be %le or %lf.  X3J11 didn't change that.

[I cite the Old Testament here because the original poster appealed to it.]



More information about the Comp.lang.c mailing list