Looks like I figured it out on my own. This code works:
Code:
#include <stdio.h>
int main ()
{
int i;
float f[100];
FILE *fp;
fp = fopen ("myfile.txt","r");
for( i = 0; i < 50; i++ ) {
if(fscanf (fp, "%f\n", &f[i]) !=1) {
break;
}
}
fclose (fp);
printf ("I have read: %f and %f and %f\n",f[0],f[1],f[2]);
return 0;
}
But there is one strange problem.
Code:
[wsduvall@Asar mpi]$ ./a.out
I have read: 3.141600 and 23.120001 and 12.143000
[wsduvall@Asar mpi]$ cat myfile.txt
3.141600
23.12
12.143
Notice the difference between what the program is reading and what is actually in the file? It might have something to do with the precision... any ideas?