Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!ut-emx!walt.cc.utexas.edu!pmaniac From: pmaniac@walt.cc.utexas.edu (Noah Friedman) Newsgroups: comp.lang.c Subject: Re: scanf doesn't work for variables of type double Summary: use %lf for doubles Message-ID: <18597@ut-emx.UUCP> Date: 19 Sep 89 20:45:46 GMT References: <12988@uhnix1.uh.edu> Sender: news@ut-emx.UUCP Reply-To: pmaniac@walt.cc.utexas.edu (Noah Friedman) Organization: The University of Texas at Austin, Austin, Texas Lines: 21 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 > double vec[V]; > int i; > for (i=0;i scanf("%f ",&vec[i]); I tried your program on a Sun2/50 (running UNIX system V) and got the same results. I know from past experience that the same thing happens on my IBM PC (using Turbo-C, which is supports ANSI C). My suggestion is to use "%lf" and don't worry about it. Noah Friedman pmaniac@walt.cc.utexas.edu