Re: [AMBER] fscanf

From: Daniel Roe <droe.nist.gov>
Date: Tue, 26 Jan 2010 17:12:13 -0500

I believe that sscanf and fscanf require that you pass the addresses of
the variables you want to set, i.e.

float f;
fscanf(FILE,"%f",&f);

works, but

fscanf(FILE,"%f",f);

doesn't. You can try using the address operator on your arguments, like

fscanf(pf,"%f %f %f",&(a[n].x), &(a[n].y), &(a[n].z));

and see if that helps.

-Dan

Lixia Jin Day wrote:
> Below is my testing code. When I compile it give me this warning:
> nab -v testing.nab
> cpp cmd: /usr/local/amber11/bin/ucpp -l -I/usr/local/amber11/include
> testing.nab
> nab2c cmd: /usr/local/amber11/bin/nab2c -nfname testing.nab
> cc cmd: gcc -I/usr/local/amber11/include testing.c
> /usr/local/amber11/lib/libnab.a /usr/local/amber11/lib/libsym.a
> /usr/local/amber11/lib/carpack.a /usr/local/amber11/lib/clapack.a
> /usr/local/amber11/lib/cblas.a /usr/local/amber11/lib/f2c.a -lm
> testing.c: In function ‘main’:
> testing.c:30: warning: format ‘%f’ expects type ‘float *’, but argument 3
> has type ‘REAL_T *’
> testing.c:30: warning: format ‘%f’ expects type ‘float *’, but argument 4
> has type ‘REAL_T *’
> testing.c:30: warning: format ‘%f’ expects type ‘float *’, but argument 5
> has type ‘REAL_T *’
>
>
> When I use sscanf(line, "%f %f %f",a[n].x, a[n].y, a[n].z); instead of
> fscanf(pf,"%f %f %f",a[n].x, a[n].y, a[n].z); I get the same warning.
> Ignoring the warning I ran the exe to find that all the output was 0.00000
>
> Please advice where in the code is wrong. Thank you!
>
> Lixia
>
> //////////////////////code
> //testing
> string line;
> point a[4];
> int n;
> file pf;
>
>
> pf=fopen("data.txt","r");
> line=getline(pf);
> printf("%s\n",line);
> for(n=0;n<4;n=n+1) {
> fscanf(pf,"%f %f %f",a[n].x, a[n].y, a[n].z);
> printf ("%f, %f, %f",a[n].x,a[n].y,a[n].z);
> printf ("\tdone!\n");
> }
> fclose(pf);
> _______________________________________________
> AMBER mailing list
> AMBER.ambermd.org
> http://lists.ambermd.org/mailman/listinfo/amber
>

-- 
Daniel R. Roe, Ph.D.
Research Chemist
National Institute of Standards and Technology
100 Bureau Drive, Stop 8443
Gaithersburg, MD 20899-8443
(301) 975-8741
_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Tue Jan 26 2010 - 14:30:03 PST
Custom Search