阅读465 返回首页    go 阿里云 go 技术社区[云栖]


一些库函数实现(注意安全性检查)

微笑十进制转二进制 

安全性检查略

 

微笑atoi 基本版:抛出异常

int f_convert(char *str) throw (char*)
{
//数字字符串转换为int型 
    if(!str){
      char*a="pointer is NULL\n";
      throw(a);
     }
 int tmp=0;
 int len=strlen(str);
 for(int i=0;i<len;i++){
  if(!isdigit(str[i])){
   char*b="!digit\n";
   throw(b);
  }
   tmp*=10;tmp+=str[i]-'0';
 }
    return tmp; 
}

atoi 高级版:判断溢出

测试数据:

微笑指数函数、幂函数自己实现

//位运算加分治+安全性检查
 

微笑strcpy  字符串拷贝

最后更新:2017-04-03 12:55:52

  上一篇:go Dev GridControl 小结
  下一篇:go 二叉树的建立(先中后序)