1. 程式人生 > >C語言幾個函式用法小結

C語言幾個函式用法小結

1.char *ultoa(unsigned long value,char *string,int radix) 

將無符號整型數value轉換成字串並返回該字串,radix為轉換時所用基數 

2.char *ltoa(long value,char *string,int radix) 

將長整型數value轉換成字串並返回該字串,radix為轉換時所用基數 

3.char *itoa(int value,char *string,int radix)

將整數value轉換成字串存入string,radix為轉換所用基數. 

4.double atof(char *nptr) 
將字串nptr轉換成雙精度數,並返回這個數,錯誤返回0 
5.int atoi(char *nptr) 
將字串nptr轉換成整型數, 並返回這個數,錯誤返回0 
6.long atol(char *nptr) 
將字串nptr轉換成長整型數,並返回這個數,錯誤返回0 
7.double strtod(char *str,char **endptr) 
將字串str轉換成雙精度數,並返回這個數, 
8.long strtol(char *str,char **endptr,int base) 

將字串str轉換成長整型數, 並返回這個數,

9.char *itoaint value, char *string,int radix); value欲轉換的資料。string:目標字串的地址。radix:轉換後的進位制數,可以是10進位制、16進位制等。

10.void *memcpy(void * __restrict /*s1*/,const void * __restrict /*s2*/, size_t /*n*/)

注意一點無論S1和S2是什麼型別指標,size_t只指S1指標指向變數所對應的位元組數量多少,而不是該

變數型別的個數多少。可是配合sizeof來計算該指標變數對應的位元組數

11.sizeof和strlen的區別,前者是變數佔用位元組數量,後者是字串佔用位元組多少以\0計算結束。