hart@blackjack.dt.navy.mil (Michael Hart) (07/17/90)
Yes, this is probably a stupid, obvious (RTFM)
question to all you C geniuses, but, I have
RTFM and the FM is not very explicit. What
a surprise.
I am trying to input a floating point number into
my prog, in the format nnnnnn.mm . Using the following
code, I see that it is reading the correct number
of chars, but apparantly either is not storing them
the way I want, or just not printing them out.
Please respond via E-mail; that way I won't get too
many flames for this question.
BTW,
#define SYSTEM SGI4D/25
#define OS 3.2.1
thanx
code follows:
=======================================
#include <stdio.h>
float *number;
char *buffer[80];
int *c1;
main()
{
printf("Please enter a number with a decimal point : ");
gets(buffer);
printf("\n");
sscanf(buffer,"%f%n",&number,&c1);
printf("(debug: num of chars read was : %d)\n",c1);
printf("\n");
printf("\n\n\nThe data as entered:\n");
printf("decimal number : %#6.2f\n",number);
printf("\n");
}
========================================
--
-------------------------------------------------------------------------------
Michael G. Hart hart@blackjack.dt.navy.mil / mhart@dtrc.dt.navy.mil
DTRC/DoD | "Wherever you go, there you are."- me
DISCLAIMER: If you want the Navy's opinion, talk to Secretary Cheney.
--
-------------------------------------------------------------------------------
Michael G. Hart hart@blackjack.dt.navy.mil / mhart@dtrc.dt.navy.mil
DTRC/DoD | "Wherever you go, there you are."- me
DISCLAIMER: If you want the Navy's opinion, talk to Secretary Cheney.
shodsdon@elrond.CalComp.COM (Steve V. Hodsdon) (07/19/90)
In article <hart.648221206@blackjack> hart@blackjack.dt.navy.mil (Michael Hart) writes:
#
#Yes, this is probably a stupid, obvious (RTFM)
#question to all you C geniuses, but, I have
#RTFM and the FM is not very explicit. What
#a surprise.
#
#I am trying to input a floating point number into
#my prog, in the format nnnnnn.mm . Using the following
#code, I see that it is reading the correct number
#of chars, but apparantly either is not storing them
#the way I want, or just not printing them out.
#
#Please respond via E-mail; that way I won't get too
#many flames for this question.
Tried to, can't get there from here :-)
#thanx
#
#code follows:
#=======================================
#[...>
# sscanf(buffer,"%f%n",&number,&c1);
^^
-> should be %lf
#[...]>
#========================================
#
#--
#-------------------------------------------------------------------------------
#Michael G. Hart hart@blackjack.dt.navy.mil / mhart@dtrc.dt.navy.mil
#DTRC/DoD | "Wherever you go, there you are."- me
#DISCLAIMER: If you want the Navy's opinion, talk to Secretary Cheney.
This is a mistake that I make all the time, also. Someday...
--
Steve Hodsdon
CalComp Display Products Division, A Lockheed Co.
65 River Rd, Hudson, NH 03051-0908
shodsdon@elrond.CalComp.COM (603) 885-8324 {decvax|harvard}!elrond!shodsdon
karl@haddock.ima.isc.com (Karl Heuer) (07/20/90)
In article <2834@elrond.CalComp.COM> shodsdon@elrond.UUCP (Steve V. Hodsdon) writes: >In article <hart.648221206@blackjack> hart@blackjack.dt.navy.mil (Michael Hart) writes: >>Please respond via E-mail... > >Tried to, can't get there from here :-) Please, folks, don't use USENET as a substitute for faulty mail. If your mailer can't understand the address, then just sit on your hands and let somebody else answer the question. (Especially when your answer is wrong, 'cause then we gurus might have to do damage control.) >> sscanf(buffer,"%f%n",&number,&c1); > ^^ -> should be %lf `%lf' is the correct scanf format for objects of type `double', but (after fixing the bug that he had an extra `*' in all the declarations) the type of the object in question was `float', for which `%f' is indeed correct. (Note that the situation is different for printf, where the context is such that float would promote to double, so `%f' serves for both.) Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint
max@pnet51.orb.mn.org (Max Tardiveau) (07/21/90)
karl@haddock.ima.isc.com (Karl Heuer) writes : >Please, folks, don't use USENET as a substitute for faulty mail. If your >mailer can't understand the address, then just sit on your hands and let >somebody else answer the question. (Especially when your answer is wrong, >'cause then we gurus might have to do damage control.) I thought there was an unspoken tradition that noone can call himself or herself a guru (except K&R). I always thought that others can call you and recognize you as a guru, but that you should not apply that term to yourself. Guess I was wrong. Max -------------------------------------------------------------------- Claimer : I speak for the entire planet. Anyone who disagrees is out of this world. UUCP: {amdahl!bungia, uunet!rosevax, crash}!orbit!pnet51!max ARPA: crash!orbit!pnet51!max@nosc.mil INET: max@pnet51.orb.mn.org
diamond@tkou02.enet.dec.com (diamond@tkovoa) (07/23/90)
In article <2899@orbit.cts.com> max@pnet51.orb.mn.org (Max Tardiveau) writes: >karl@haddock.ima.isc.com (Karl Heuer) writes : >>... we gurus ... >I thought there was an unspoken tradition that noone can call himself >or herself a guru (except K&R). I always thought that others can call >you and recognize you as a guru, but that you should not apply that >term to yourself. Guess I was wrong. Perhaps after enough people have called Karl Heuer a guru, he is allowed to agree. He's probably even more of a guru than K&R, in terms of making fewer mistakes. -- Norman Diamond, Nihon DEC diamond@tkou02.enet.dec.com This is me speaking. If you want to hear the company speak, you need DECtalk.
evil@arcturus.uucp (Wade Guthrie) (07/24/90)
Karl Heuer writes: > (Especially when your answer is wrong, > 'cause then we gurus might have to do damage control.) Geez. I'm assuming an implied smiley face. -- Wade Guthrie (evil@arcturus.UUCP) | "He gasped in terror at what sounded Rockwell International; Anaheim, CA | like a man trying to gargle while My opinions, not my employer's. | fighting off a pack of wolves" | Hitchhiker's Guide