problem with precision when reading from file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello, 

I wrote the following program:



#include <stdio.h> 
#include <math.h> 
#include <stdlib.h> 
#include <time.h> 
#include <string.h> 

int main() 
{ 

FILE *fp; 
fp = fopen("test.c", "r"); 
if (fp == NULL){ 
    printf("Error opening input file\n"); 
    exit(1); 
} 

float var1, var2, var3; 

fscanf(fp,"%f",&var1); 
fscanf(fp,"%f",&var2); 
fscanf(fp,"%f",&var3); 

if (var1!=0.01) printf("var1 = %g\n",var1); 
if (var2!=5) printf("var2 = %g\n",var2); 
if (var3!=0.6) printf("var3 = %g\n",var3);



Where test.c contains the following: 

0.01 
5 
0.6



When I run the program I get the following output: 

var1 = 0.01 
var3 = 0.6 



I expected to get no output. Can you explain what is the problem? 

Thanks, 
Anna


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux