Hello,
I have quite a frustrating problem.
Here is some code I am running:
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int main(void)
{
char *c_time0 = "000", *c_time1 = "000", *c_time2 = "000", *c_time3 = "000";
char *s_time0 = "000", *s_time1 = "000", *s_time2 = "000", *s_time3 = "000";
double p_time0 = 0.001;
double r_time0 = (p_time0*1000)-(floor(p_time0)*1000);
double n_time0 = (0.001*1000)-0;
double p_time1 = 1.001;
double r_time1 = (p_time1*1000)-(floor(p_time1)*1000);
double n_time1 = (1.001*1000)-1000;
double p_time2 = 2.001;
double r_time2 = (p_time2*1000)-(floor(p_time2)*1000);
double n_time2 = (2.001*1000)-2000;
double p_time3 = 3.001;
double r_time3 = (p_time3*1000)-(floor(p_time3)*1000);
double n_time3 = (3.001*1000)-3000;
itoa(r_time0, c_time0,10);
itoa(r_time1, c_time1,10);
itoa(r_time2, c_time2,10);
itoa(r_time3, c_time3,10);
itoa(n_time0, s_time0,10);
itoa(n_time1, s_time1,10);
itoa(n_time2, s_time2,10);
itoa(n_time3, s_time3,10);
printf("Result = %f %s %f %s \n", p_time0, c_time0, r_time0, s_time0);
printf("Result = %f %s %f %s \n", p_time1, c_time1, r_time1, s_time1);
printf("Result = %f %s %f %s \n", p_time2, c_time2, r_time2, s_time2);
printf("Result = %f %s %f %s \n", p_time3, c_time3, r_time3, s_time3);
return 0;
}
When I compile and run I get the following output:
Result = 0.001000 1 1.000000 1
Result = 1.001000 0 1.000000 0
Result = 2.001000 0 1.000000 0
Result = 3.001000 0 1.000000 0
THis first one is fine, returning a 1, but the others are wacked and return 0s. What is up with that and what can I do to get the correct results.
Thanks in advance.
B"H
Brak
I have quite a frustrating problem.
Here is some code I am running:
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int main(void)
{
char *c_time0 = "000", *c_time1 = "000", *c_time2 = "000", *c_time3 = "000";
char *s_time0 = "000", *s_time1 = "000", *s_time2 = "000", *s_time3 = "000";
double p_time0 = 0.001;
double r_time0 = (p_time0*1000)-(floor(p_time0)*1000);
double n_time0 = (0.001*1000)-0;
double p_time1 = 1.001;
double r_time1 = (p_time1*1000)-(floor(p_time1)*1000);
double n_time1 = (1.001*1000)-1000;
double p_time2 = 2.001;
double r_time2 = (p_time2*1000)-(floor(p_time2)*1000);
double n_time2 = (2.001*1000)-2000;
double p_time3 = 3.001;
double r_time3 = (p_time3*1000)-(floor(p_time3)*1000);
double n_time3 = (3.001*1000)-3000;
itoa(r_time0, c_time0,10);
itoa(r_time1, c_time1,10);
itoa(r_time2, c_time2,10);
itoa(r_time3, c_time3,10);
itoa(n_time0, s_time0,10);
itoa(n_time1, s_time1,10);
itoa(n_time2, s_time2,10);
itoa(n_time3, s_time3,10);
printf("Result = %f %s %f %s \n", p_time0, c_time0, r_time0, s_time0);
printf("Result = %f %s %f %s \n", p_time1, c_time1, r_time1, s_time1);
printf("Result = %f %s %f %s \n", p_time2, c_time2, r_time2, s_time2);
printf("Result = %f %s %f %s \n", p_time3, c_time3, r_time3, s_time3);
return 0;
}
When I compile and run I get the following output:
Result = 0.001000 1 1.000000 1
Result = 1.001000 0 1.000000 0
Result = 2.001000 0 1.000000 0
Result = 3.001000 0 1.000000 0
THis first one is fine, returning a 1, but the others are wacked and return 0s. What is up with that and what can I do to get the correct results.
Thanks in advance.
B"H
Brak