C Func atoi - sonkoni/Koni-Wiki GitHub Wiki

stdlib.h

atoi, atol, atoll

μ •μˆ˜ν¬λ©§μ˜ λ¬Έμžμ—΄μ„ μ‹€μˆ˜λ‘œ λ³€ν™˜ (Ascii TO Int)

int        atoi(const char *str);
long       atol(const char *str);
long long  atoll(const char *str);
// str: μ •μˆ˜ν¬λ©§ λ¬Έμžμ—΄
// μ •μˆ˜ν¬λ©§μ˜ λ¬Έμžμ—΄μ„ μ •μˆ˜λ‘œ λ³€ν™˜ν•˜μ—¬ λ°˜ν™˜. μ‹€νŒ¨ν•˜λ©΄ 0 λ°˜ν™˜.
// - 숫자λ₯Ό λ³€ν™˜ν•˜λ‹€κ°€ μ•ŒνŒŒλ²³, 영문자, 특수문자 λ“± 문자 λ§Œλ‚˜λŠ” μ§€μ μ—μ„œ μ€‘λ‹¨ν•œλ‹€.
// - μ²˜μŒλΆ€ν„° μˆ«μžκ°€ μ•„λ‹ˆλ©΄ μ€‘λ‹¨ν•˜κ³  0 λ°˜ν™˜ν•œλ‹€.
// - 쀑간에 곡백을 λ§Œλ‚˜λ„ μ’…λ£Œλœλ‹€.
// - μ²˜μŒλΆ€ν„° 곡백이면 κ·Έ 곡백은 κ±΄λ„ˆλ›΄λ‹€.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    char *str = "283";    // μ •μˆ˜ν¬λ©§ λ¬Έμžμ—΄
    int num = atoi(str);  // μ •μˆ˜λ‘œ λŒ€μΉ˜
    printf("%s : %d", str, num);
    return 0;
}
// 283 : 283
⚠️ **GitHub.com Fallback** ⚠️