虽然注册博客很多年了,但是一直太懒,只是潜水,只动鼠标,从来没有动过键盘。
最近本人升级了,当了父亲,故而想写点和记录点东西。
本人也是码农一个,先贴段代码供大家欣赏:
这是一个比较古老的C语言函数itoa,把一个整数转换为字符串返回:
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <fcntl.h> #include <errno.h> #include <math.h> #include <poll.h> #include <unistd.h> #include <dirent.h> #include <sys/select.h> #include <string.h> char * itoa(int n) { int i, tmp, flag; char str[32], t, *start, *end, *ret; i = 0; memset(str, 0, sizeof(str)); if (n < 0) { flag = 1; n = -n; } do { tmp = n%10; n = n/10; str[i++] = '0' + tmp; } while (n > 0); if (flag) str[i++] = '-'; ret = malloc(i+1); memcpy(ret, str, i+1); start = ret; end = ret + i - 1; while (start < end) { t = *start; *start ++ = *end; *end -- = t; } return ret; }