C Linux下的itoa函式

2021-05-18 00:53:09 字數 509 閱讀 2576

上篇文章說到linux需要itoa函式,下面我就提供乙份跨平台的itoa函式。

這個函式會返回字串的長度,在某些場合下會很有用。

//return the length of result string. support only 10 radix for easy use and better performance

int my_itoa(int val, char* buf)

u = (unsigned int)val;

b = p;

dowhile (u > 0);

len = (int)(p - buf);

*p-- = 0;

//swap

dowhile (b < p);

return len;

}

這個實現的典型速度大概是180毫秒左右。作為對比,mfc自帶的itoa耗時是320毫秒左右。用snprintf的實現就不要出來比速度了,不是乙個級別的。

C Linux下的itoa函式

上篇文章說到linux需要itoa函式,下面我就提供乙份跨平台的itoa函式。return the length of result string.support only 10 radix for easy use and better performance int my itoa int va...

C linux下實現ls 函式遍歷目錄

需求 在linux下遍歷目錄,輸出目錄中各檔名。include dir opendir const char dir path struct dirent readdir dir dirp int closedir dir dirp int lstat const chat filename,str...

itoa函式的實現

itoa 函式的功能是將乙個整數轉換為乙個字串,例如12345,轉換之後的字串為 12345 123轉換之後為 123 include 反轉字串 char reverse char s return s 功能 整數轉換為字串 char s 的作用是儲存整數的每一位 char my itoa int ...