- 论坛徽章:
- 0
|
本帖最后由 我是个野鸭子 于 2014-10-21 17:04 编辑
编译环境RHEL6.4+GCC环境
具体源代码如下:
- #include <stdio.h>
- #include <stdlib.h>
- void main(void);
- char* itoa(int, char*, int);
- void main(void)
- {
- int num = 100;
- char str[25];
- itoa(num, str, 10);
- printf("The number 'num' is %d and the string 'str' is %s. \n", num, str);
- }
- char* itoa(int value, char* result, int base)
- {
- char* ptr = result, *ptr1 = result, tmp_char;
- int tmp_value;
- //check that the base if valid
- if (base < 2 || base > 36) { *result = '/0'; return result; }
- do {
- tmp_value = value;
- *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"
- [35 + (tmp_value - value * base)];
- } while (value);
- //apply negative sign
- if (tmp_value < 0) *ptr++ = '-';
- *ptr-- = '/0';
- while (ptr1 < ptr)
- {
- tmp_char = *ptr;
- *ptr-- = *ptr1;
- *ptr1++ = tmp_char;
- }
- return result;
- }
复制代码 请问什么地方core dump了?
还有代码中如下行是什么意思?
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"
[35 + (tmp_value - value * base)]; |
|