Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!ames!uhccux!munnari.oz.au!mimir!hugin!augean!sirius!nt!levels!marwk From: MARWK@levels.sait.edu.au Newsgroups: comp.lang.c Subject: Re: scanf doesn't work for variables of type double Message-ID: <1691@levels.sait.edu.au> Date: 18 Sep 89 10:29:41 GMT References: <12988@uhnix1.uh.edu> Organization: Sth Australian Inst of Technology Lines: 25 In article <12988@uhnix1.uh.edu>, jsmng@csune.cs.uh.edu writes: > I used the following program trying to read in 5 numbers interactively. > As a test, I typed in 1.0 1.0 1.0 1.0 1.0 as input but the output is > about 0.47 (approximately I forget the exact value but it is far from 1). > When I changed the type of vec[] to be float. Everything is fine. > 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). > > #include > #define V 5 > main() > { > double vec[V]; > int i; > for (i=0;i scanf("%f ",&vec[i]); > for (i=0;i printf("%f ",vec[i]); > } You must use: scanf("%lf", &var) for doubles (long floats). Ray