自定義實現strcmp,atoi,itoa函式

2021-09-28 23:26:00 字數 1322 閱讀 5506

1.mystrcmp函式,字串比較 「abc」< 「x」 ;「abc」== 「abc」;「ab」 >「aa」

第乙個大於第二個則返回正數,相等返回0,第乙個小於第二個返回負數。

#include

#include

intmystrcmp

(const

char

*str1,

const

char

*str2)

int tmp=0;

while

((tmp=

*str1-

*str2)==0

&&*str1!=

'\0'

)return tmp;

}int

main()

2.myatoi函式

將字串轉成數字,「123」->123

#include

#include

#include

intmyatoi

(const

char

*str)

int tmp=0;

int ***=1;

while

(*str==

' '||

*str==

'+')

//處理空格和「+」if(

*str==

'-')

//處理負數

while

(isdigit

(*str)

)return tmp****;

}int

main()

執行結果如下:

3.myitoa函式,數字轉字元

#include

#include

#include

void

reversestr

(char

*str)

//逆序輸出

}void

myitoa

(char

*buf,

int n)

//數字轉字元

int i=0;

//123->"321"

while

(n!=0)

buf[i]

='\0'

;reversestr

(buf);}

intmain()

自定義Toast實現自定義Toast布局

平時我們使用toast的時候都是這樣的一種方法 toast toast toast.maketext context,duration 現在我們來自定義下toast的布局,首先看下toast建立時的源 public static toast maketext context context,char...

實現自定義IFormattable

using system using system.collections using system.linq using system.text using system.collections.generic using system.runtime.serialization namespac...

自定義tabcontrol實現

using system using system.collections generic using system.drawing using system.linq using system.text using system.windows forms namespace shengxinso...