ragg0270@uxa.cso.uiuc.edu (Richard Alan Gerber) (09/30/90)
A further SAS/C double question (since I can't get hold of them on the weekend). I am reading an ASCII file that contains columns of data w/ a construct like: FILE *fp; float *num1,*num2,*num3; int n; [...] num1 = (float *)AllocMem(sizeof(float), MEMF_PUBLIC|MEMF_CLEAR); etc... n = fscanf(fp,"%e%e%e\n",num1,num2,num3); [...] This works like a charm. But when I replace "float" with "double" everywhere it gives me total garbage. I don't know if the problem is with me (programming error), compiler settings or a compiler bug. Thanks for any help. Richard Gerber gerber@rigel.astro.uiuc.edu
walker@unx.sas.com (Doug Walker) (10/02/90)
In article <1990Sep29.193407.28644@ux1.cso.uiuc.edu> ragg0270@uxa.cso.uiuc.edu (Richard Alan Gerber) writes: >n = fscanf(fp,"%e%e%e\n",num1,num2,num3); > > >This works like a charm. But when I replace "float" with "double" >everywhere it gives me total garbage. I don't know if the problem is >with me (programming error), compiler settings or a compiler bug. >Thanks for any help. Try replacing your %e's with %le's when you switch to double. You have to tell fscanf that you are passing pointers to double instead of pointers to float. ***** =*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 = *|. o.| || | o |// For all you do, this bug's for you! ====== usenet: ...mcnc!rti!sas!walker plink: dwalker bix: djwalker
jmeissen@oregon.oacis.org ( Staff OACIS) (10/02/90)
In article <1990Sep29.193407.28644@ux1.cso.uiuc.edu> ragg0270@uxa.cso.uiuc.edu (Richard Alan Gerber) writes: >A further SAS/C double question (since I can't get hold of them on the >weekend). [....] >n = fscanf(fp,"%e%e%e\n",num1,num2,num3); > >This works like a charm. But when I replace "float" with "double" >everywhere it gives me total garbage. You also need to change the format string, since it still assumes it is storing a 32-bit quantity instead of a 64-bit quantity. I believe it is "%le%le%le". -- John Meissen .............................. Oregon Advanced Computing Institute jmeissen@oacis.org (Internet) | "That's the remarkable thing about life; ..!sequent!oacis!jmeissen (UUCP) | things are never so bad that they can't jmeissen (BIX) | get worse." - Calvin & Hobbes