示例:
/*** @brief how about recursive-forward-1? show you here.* @author wen`xuanpei* @email 15873152445@163.com(query for any question here)*/
#define _CRT_SECURE_NO_WARNINGS//support c-library in Microsoft-Visual-Studio
#include <stdio.h>static char *uint2rstr_nonzero(char *str, unsigned int ui){if(ui){*str++ = ui % 10 + '0';return uint2rstr_nonzero(str, ui / 10);}return str;
}
static char * uint2rstr(char *str, unsigned int ui){if( !ui )*str++ = '0';elsestr = uint2rstr_nonzero(str, ui);*str = '\0';return str;
}int main(){char str[20] = {};char *pt = NULL;pt = uint2rstr(str, 123U), printf("'%s', %d\n", str, pt - str);pt = uint2rstr(str, 0U), printf("'%s', %d\n", str, pt - str);getchar();return 0;
}
1)编译运行
2)要点分析
1)在每一次函数调用层次增加之前做处理
2)每一次处理,取得尾巴数字,输出到字符数组,从而得到逆序的字符串数字
尾声:
其它不明白的地方不用过于纠结,那只是在浪费时间。学得多了,回过头来看自然融会贯通。