mirror of https://github.com/cy384/ssheven.git
fix printing of negative numbers
This commit is contained in:
parent
1ae0c0848f
commit
c97e080173
|
@ -177,6 +177,7 @@ void print_int(int d)
|
|||
|
||||
char buffer[12] = {0};
|
||||
int i = 10;
|
||||
int negative = 0;
|
||||
|
||||
if (d == 0)
|
||||
{
|
||||
|
@ -184,13 +185,21 @@ void print_int(int d)
|
|||
i = -1;
|
||||
}
|
||||
|
||||
if (d < 0)
|
||||
{
|
||||
negative = 1;
|
||||
d *= -1;
|
||||
}
|
||||
|
||||
for (; d > 0; i--)
|
||||
{
|
||||
buffer[i] = itoc[d % 10];
|
||||
d /= 10;
|
||||
}
|
||||
|
||||
print_string(buffer+i+1);
|
||||
if (negative) buffer[i] = '-';
|
||||
|
||||
print_string(buffer+i+1-negative);
|
||||
}
|
||||
|
||||
void print_string(const char* c)
|
||||
|
|
Loading…
Reference in New Issue