From: Eric Backus Subject: Re: scanf woes To: richards AT sequent DOT com (Richard Shields) Date: Thu, 7 Jan 93 13:54:19 PST Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Mailer: Elm [revision: 66.25] > Has anyone had any trouble using scanf to read in a floating point value? > > I tried this in my code: > > double amount; > > scanf("%f", amount); > printf("amount = %10.2f\n", amount); > > > When I run the program and enter 4.25 the printf statement prints 0.00. > > I have successfully used scanf to read in a string but anything else seems > to fail. > > -Rich Unlike printf(), scanf() needs to be passed a pointer to the variable you are assigning. You were able to read a string because a string is a pointer to char. Change your program to say scanf("%f", &amount); and all should work fine. -- Eric Backus ericb AT lsid DOT hp DOT com (206) 335-2495