0$房天下问答|两种方法实现字符串转换为数字$https://m.fang.com/ask/ask_1799369.html$https://static.soufunimg.com/common_m/m_public/201511/images/asksharedefault.png
packc/pages/ask/detail/detail?askid=1799369
共1个回答
-
-
-
梦回 草原
丨Lv 0
只做了正整数的情况,你看是不你想要的#include <stdio.h>#include <string.h>int String2Int1(char *pHead, char *pEnd){ int retVal=0; while (pEnd>=pHead) { retVal*=10; retVal+=*pHead-'0'; pHead++; } return retVal;}int String2Int2(char *pHead, char *pEnd){ if (pHead==pEnd) { return *pHead - '0'; } else { return 10 * String2Int2(pHead, pEnd-1)+*pEnd-'0'; }}int main(){ char *p="123456"; int r=0,t=0; r=String2Int2(p,p+strlen(p)-1); printf("%d\n",r); t=String2Int2(p,p+strlen(p)-1); printf("%d\n",t); return 0;}
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。

关注成功