Article View: gnu.gcc.help
Article #51651a real simple C question about scanf and user input
From: Edward J. Hartnett
Date: Thu, 29 Apr 1993 15:52
Date: Thu, 29 Apr 1993 15:52
35 lines
1623 bytes
1623 bytes
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!
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:
<EJH.93Apr29155213@khonshu.colorado.edu>Path:
arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!boulder!colorado.edu!ejhShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,f67b5e2b3821428a,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1993-04-29 15:16:19 PST Newsgroups: gnu.gcc.help Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!boulder!colorado.edu!ejh From: ejh@khonshu.colorado.edu (Edward J. Hartnett) Subject: a real simple C question about scanf and user input Message-ID: <EJH.93Apr29155213@khonshu.colorado.edu> Sender: news@colorado.edu (The Daily Planet) Nntp-Posting-Host: khonshu.colorado.edu Organization: CIRES, University of Colorado Date: 29 Apr 93 15:52:13 Lines: 36