C语言atoi函数的用法
生活随笔
收集整理的這篇文章主要介紹了
C语言atoi函数的用法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#include < stdlib.h > int atoi(const char *nptr);
用法:將字符串里的數(shù)字字符轉(zhuǎn)化為整形數(shù)。返回整形值。
注意:轉(zhuǎn)化時跳過前面的空格字符,直到遇上數(shù)字或正負符號才開始做轉(zhuǎn)換,而再遇到非數(shù)字或字符串結(jié)束時(’/0’)才結(jié)束轉(zhuǎn)換,并將結(jié)果返回。
例:
#include <stdio.h> #include <stdlib.h>int main() {char *ptr1 = "-12345.12";char *ptr2 = "+1234w34";char *ptr3 = " 456er12";char *ptr4 = "789 123";int a,b,c,d;a = atoi(ptr1);b = atoi(ptr2);c = atoi(ptr3);d = atoi(ptr4);printf("a = %d, b = %d, c = %d, d = %d\n", a,b,c,d);return 0; }輸出結(jié)果:a = -12345, b = 1234, c = 456, d = 789
總結(jié)
以上是生活随笔為你收集整理的C语言atoi函数的用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 烈火雄心2剧情介绍
- 下一篇: 多囊卵巢综合征中医治疗