🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #51655

Re: a real simple C question about scanf and user input

#51655
From: Reinhard Schiedermeier
Date: Fri, 30 Apr 1993 14:07
39 lines
2114 bytes
Edward J. Hartnett (ejh@khonshu.colorado.edu) wrote:

: Hi, Here's a section from my program:

: main() {
:   int lat_zone;
:   int cell, isccp_cell, isccp_num;
:   float lat, lon;
:   float centlat[NUM_LAT_ZONES], centlon[MAX_ISCCP_NUM];

:   equare();

:   printf("Please enter the lat and long in degrees: ");
:   scanf("%f%f",&lat, &lon);
:   printf("%f, %f",lat,lon);

: And here's what I get when I try to run this program:

: > iscgrid
: Please enter the lat and long in degrees: 1.0, 1.0
: Segmentation fault
: >


: So obviously something is wrong with my scanf call, but what? I asked
: the guru here and he said he never uses scanf, he uses fgets to read
: from the input to a character array and then uses scanf to read that.
: Is this common proactice? Is there some better way? All advice
: welcome!
You didn't parse the comma between the two floats.
Write scanf("%f,%f"... in your source.
Why does your guru prefer sscanf? I don't see any reason.

: Thanks.
: --
: Such wind as scatters young men through the world, to seek their
: fortunes farther than at home, where small experience grows.
:                                                                  - Shakespeare
: Edward Hartnett	   ejh@khonshu.colorado.edu
Technical Details
Message-ID: <C6AsHD.L3B@snimucgw.stm.mchp.sni.de>
Path: arc1-ca.pugleaf.net!gmd.de!ira.uka.de!howland.reston.ans.net!noc.near.net!uunet!mcsun!Germany.EU.net!thoth.mchp.sni.de!snimucgw!stmsd113
References: <EJH.93Apr29155213@khonshu.colorado.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,f67b5e2b3821428a
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-04-30 06:24:57 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!ira.uka.de!howland.reston.ans.net!noc.near.net!uunet!mcsun!Germany.EU.net!thoth.mchp.sni.de!snimucgw!stmsd113
From: stmsd113@stm.mchp.sni.de (Reinhard Schiedermeier)
Subject: Re: a real simple C question about scanf and user input
Sender: news@snimucgw.stm.mchp.sni.de (0000-news(0000))
Message-ID: <C6AsHD.L3B@snimucgw.stm.mchp.sni.de>
Date: Fri, 30 Apr 1993 14:07:57 GMT
Reply-To: schiedi%SARAH%deejai%d255s004.zfe.siemens.de@mail.Germany.EU.net
References: <EJH.93Apr29155213@khonshu.colorado.edu>
Organization: Siemens Nixdorf Informationssysteme AG, Munich, W. Germany
X-Newsreader: TIN [version 1.1 PL9]
Lines: 40