Path: utzoo!attcan!telly!moore!eastern!egsgate!f701.n250.z1.fidonet.org!Rob.Doucette From: Rob.Doucette@f701.n250.z1.fidonet.org (Rob Doucette) Newsgroups: comp.lang.c Subject: sprintf badness Message-ID: <313.27B80377@egsgate.fidonet.org> Date: 11 Feb 91 13:52:00 GMT Sender: ufgate@egsgate.fidonet.org (newsout1.26) Organization: FidoNet node 1:250/701 - MetroHUB 7, Thornhill ON Lines: 24 >main () >{ > char buf[90]; > int i,j; > double k; > sprintf(buf,"%.4d%07.2f%.4d",45,445.34,1234); > printf("buf = %s\n",buf); > sscanf(buf,"%4d%7f%4d",&i,&k,&j); > printf("i = %d j = %d k= %7.2f",i,j,k); >} >------------ output of the above program ---------------- >buf = 00450445.341234 >i = 45 j = 1234 k= 8840025108807417000.00 >--- D'Bridge 1.30/001331 > * Origin: EGSGATE Fidonet<->Usenet Gateway (1:250/98) >(1:250/416) Try changing line 5 to read - float k; You could instead change line 6 to read sscanf(buf, "%4.d%07.3lf%.4d", 45, 445.34, 1234); L8R. -- EGSGate Fidonet Gateway, Toronto (egsgate.fidonet.org) ...!{uunet, moore, lsuc}!eastern!egsgate