atoi、itoa、sprintf

1.atoi

作用:將字符串轉化成整形
函數原型:int atoi(const char *str)
參數:str爲要轉化的字符串
例子: atoi(“2154”);

2.itoa

作用:將整形轉化成字符串
函數原型:char *itoa (int value, char *str, int base );
參數:value需要轉化的值,str目標字符串,base進制,返回值也是一個指向目標子串的指針無錯誤返回
例子:itoa(21,str,10)

3.sprintf

作用:將參數以一定格式存到str中
函數原型:int sprintf(char *str, const char *format, …)
參數:存儲目標字符串str,format格式,…要加的字符串,錯誤返回一個負數
例子: sprintf(str, “Pi 的值 = %f”, 3.14I);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章