sprintf badness
Rob Doucette
Rob.Doucette at f701.n250.z1.fidonet.org
Tue Feb 12 00:52:00 AEST 1991
>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
More information about the Comp.lang.c
mailing list