-2

I am reading text file contains values like below

125602365 119653955 126374444 124463807 127312438 128395899

and the below code to read it.

if(!(pvtcheck(0)))
  {
     fscanf(fp,"%f",&deltime);
     printf("\ndeltime0=%f\n",deltime);    ///Actual value is 125602365, but i am getting 125602368.
  }

  if(!(pvtcheck(1)))
  {
      fscanf(fp,"\t%f",&deltime); 
      printf("\ndeltime1=%f\n",deltime);///Actual value is 119653955, but i am getting 119653952.
  }
  /// same for pvtcheck(2),pvtcheck(3),pvtcheck(4)
  if(!(pvtcheck(5)))
  {
      fscanf(fp,"\t%f",&deltime);
       printf("\ndeltime5=%f\n",deltime); ///Actual value is 128395899, but i am getting 128395896.
  }

In the Comment i have written output , any solution to not change the values

YesThatIsMyName
  • 1,585
  • 3
  • 23
  • 30
Rishi
  • 3
  • 4
  • 2
    What is the type of `deltime`? Please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Jun 19 '18 at 06:02
  • 1
    On a couple of unrelated notes: You don't need all the parentheses in the condition expressions, e.g. `if (!pvtcheck(0))` should be enough. Also, instead of doing the same thing three times in the `if` bodies, do all common things first and then use conditions to do the things that differ. Lastly, the tab `"\t"` in the `fscanf` format isn't needed. – Some programmer dude Jun 19 '18 at 06:03
  • 1
    Please learn about formatting or don't try (many users are happy to help with formatting), your attempts have broken C-syntax. Learning about indentation would also be helpful. – Yunnosch Jun 19 '18 at 06:05
  • 1
    Please study and apply the concept of making a [mcve]. – Yunnosch Jun 19 '18 at 06:05
  • 1
    Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). And again, please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Jun 19 '18 at 06:35
  • 1
    I also recommend you read [this Stack Overflow question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And all of http://idownvotedbecau.se/ to learn some reasons your question are getting negative votes. Specific examples include http://idownvotedbecau.se/nomcve/ and http://idownvotedbecau.se/beingunresponsive. – Some programmer dude Jun 19 '18 at 06:37
  • @Rishi, Your code is too poor to help you. Could you please post your full source code? – AleXelton Jun 19 '18 at 09:06
  • Please post the complete code of the function, with the definition of `deltime`. – chqrlie Jun 19 '18 at 09:09

1 Answers1

2

You need to use the double type instead of float, and the %lf format specifier for scanf instead of %f.

double deltime;

fscanf(fp, "%lf", &deltime);
printf("\ndeltime0=%lf\n", deltime);
fscanf(fp, "\t%lf", &deltime);
printf("\ndeltime1=%f\n", deltime);
...

BTW: for printf you can use either %f or %lf they both have the same meaning.

Also read this SO article

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115