閱讀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 二叉樹的建立(先中後序)