Mail Archives: djgpp/1998/07/28/11:44:53
I have this problem with a function I use to do thousands separators to
integers. Here is the code:
char * LargeInt(unsigned int bignumber)
{
int counter = -1, i, i2 = 0, sep = 0;
char string1[21];
char string2[27];
sprintf(string1, "%d", bignumber);
i = strlen(string1);
while(i >= 0)
{
if (counter < 3)
{
string2[i2] = string1[i];
counter++;
}
else
{
string2[i2] = ',';
i2++;
string2[i2] = string1[i];
counter = 1;
sep++;
}
i--;
i2++;
}
i = 0;
i2 = strlen(string1) + sep;
while(i2 >= 0)
{
tmpInt[i] = string2[i2];
i++;
i2--;
}
return tmpInt;
}
It isn't very good function but it works (on ints that is). The problem is
that I need it to support the "long long" -variables I use. Sprintf doesn't
compile with a long long as the argument (it says: "warning: int format,
different type arg (arg 3)") so I'm asking if there is an alternate
function to make a string out of an int (or, a long long in this case).
Of course, if you know how to make the separators some better way, please
tell me.
- Raw text -