atoi
Anthony J. Gabrielson
agabriel at home.tzo.org
Thu Aug 14 14:06:42 EDT 2003
Hello all,
I want to see if there is away to preserve the decimal points with
this code chunk:
int main()
{
char string[] = "T1 +24.04,T2 +25.27,TD +1.32";
char seps[] = " ,";
char *token, *T1s, *T2s, *TDs;
double T1,T2,TD;
token = strtok( string, seps );
T1s = strtok( NULL, seps );
token = strtok( NULL, seps );
T2s = strtok( NULL, seps );
token = strtok( NULL, seps );
TDs = strtok( NULL, seps );
printf("%s\t%s\t%s\n",T1s,T2s,TDs);
T1 = atol(T1s);
T2 = atol(T2s);
TD = atol(TDs);
printf("%d\t%d\t%d\n",T1,T2,TD);
return 0;
}
Output:
+24.04 +25.27 +1.32
0 1077411840 0
If I use atoi out right I get no decimal, for obvious reasons.
Thanks,
Anthony
More information about the Discuss
mailing list