stdlib.h - atoi() 使用

使用方法:stdlib.h 的函數 atoi() 接受字串當作參數,將字串中的數字轉換為 int 型態的整數範例:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    printf("%d\n", atoi("54321"));
    printf("%d\n", atoi("54.321"));
    printf("%d\n", atoi("$54321"));
    printf("%d\n", atoi("$54.321"));
    printf("%d\n", atoi("54.321%"));
    printf("%d\n", atoi("5.4321+33=?"));
     
    return 0;
}




參考:http://pydoing.blogspot.tw/2010/07/c-atoi.html

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble