Originally Posted by
nonoob
You need to use the address operator '&'
Code:
fscanf(file1, "%lf", &bb);
Thanks, I updated my code, but there is another problem. Since I assume that the length is 100 in the file. I created a text file which only have 3 double values, but my program repeat the last value for many times (I guest 98 times). How I can solve it? The following is the new code.
Code:
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
int i;
double bb;
FILE *file1 = fopen( argv[1], "r" );
if ( argc !=2 ) /* argc should be 2 for correct execution */
{
printf( "Error of input argument number" );
}
for (i=1;i<100;i++){
fscanf(file1, "%lf",&bb);
printf("%f",bb);
}
}