Author: Uri Blass
Date: 06:25:57 12/07/01
Go up one level in this thread
On December 07, 2001 at 09:17:01, Sune Fischer wrote:
>On December 07, 2001 at 09:00:27, Uri Blass wrote:
>>I got the following function but it simply does not work
>>
>>char * tostring (__int64 x, char *s)
>>{ __int64 a = x/1000000;
>> __int64 b = x%1000000;
>> if (x>1000000)
>> sprintf(s,"%d%d",a,b);
>> else
>> sprintf(s,"%d",b);
>> return s;
>>}
>>
>>I tested my program by the following code
>>char buffer[64];
>>__int64 mone;
>>mone=(1<<30);
>>printf("mone: %s\n",tostring(mone,buffer));
>>
>>and I get the wrong output 10730 when the right output should be 2^30=1073741824
>>
>>Uri
>
>Don't you need to make a cast first:
>__int64 b = x%((__int64)1000000);
>?
I tried here
Here is my newcode and it does not help
char * tostring (__int64 x, char *s)
{ __int64 a = x/((__int64) 1000000);
__int64 b = x%((__int64) 1000000);
if (x>1000000)
sprintf(s,"%d%d",a,b);
else
sprintf(s,"%d",b);
return s;
}
and later in main.c
char buffer[64];
mone=(1<<30);
printf("mone: %s\n",tostring(mone,buffer));
I get again the same wrong number 10730 on the screen.
My previous code without strings worked well so I guess I will go back to my
previous code except maybe using mone%1000000 instead of
mone-1000000*(mone/1000000);
Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.