2 * Exercise 3-4. In a two's complement number representation, our version of
3 * itoa does not handle the largest negative number, that is, the value of n
4 * equal to -(2^(wordsize-1)). Explain why not. Modify it to print that value
5 * correctly, regardless of the machine on which it runs.
8 /* In the step n = -n, it is not possible to negate the largest negative
9 * number without integer overflow.
16 void reverse(char s[]) {
18 for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
25 void itoa(int n, char s[]) {
32 s[i++] = u % 10 + '0';
33 } while ((u /= 10) > 0);
41 /* word size is 32 bits */
45 printf("Actual: %s\n", s);
46 printf("Expect: %s\n", "-147483648");
49 printf("Actual: %s\n", s);
50 printf("Expect: %d\n", INT_MIN+1);
53 printf("Actual: %s\n", s);
54 printf("Expect: %d\n", INT_MIN);