c - Parsing user input using time_t -


I think, if the user enters in t = 2.5 , then i will get 2 and 0.5 Separate 2 different variables but I am unable to do this.

Here the code is:

  $ export LT_LEAK_START = 1.5 $ echo $ LT_LEAK_START 1.5 #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Time.h> Int main () {Double D; Time_t; Long NSE; D = Stroke (getenv ("LT_LEAK_START"), NULL); T = (Time_T) d; Nsec = D (double) ((time_t) d); Remove partial part as // time_t is not always complete Printf ("d =% lf \ n", d); Printf ("t =% u, nsec =% f \ n", d, nsec); }   

Output is:

  # ./a.out d = 1.500000 t = 0, nsec = 0.000000   < / Div> 

Your output is broken. You are actually writing the value of d in the following code twice:

  nsec = d- (double) ((time_t) d); Remove partial part as // time_t is not always complete Printf ("d =% lf \ n", d); Printf ("t =% u, nsec =% f \ n", d, nsec);   

If you have written it:

  nsec = d- (double) ((time_t) d); Remove partial part as // time_t is not always complete Printf ("d =% lf \ n", d); Printf ("t =% u, nsec =% f \ n", t, nsec);   

Then you will have output:

  d = 1.500000 t = 1, nsec = 0.000000   

now Obviously you have a round error. In this situation, you remove all decimal places by specifying 0.5 to nsec , a long . Instead nsec a float .

Comments