본문 바로가기
dev/C

[C] function - atoi

by seohan1010 2024. 5. 29.

ASCII string to integer

 

 

https://pythontutor.com/render.html#mode=display

 

Python Tutor code visualizer: Visualize code in Python, JavaScript, C, C++, and Java

Please wait ... your code is running (up to 10 seconds) Write code in Python 3.11 [newest version, latest features not tested yet] Python 3.6 [reliable stable version, select 3.11 for newest] Java C (C17 + GNU extensions) C++ (C++20 + GNU extensions) JavaS

pythontutor.com

 

 

 

ex)1

 

 

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>




int main()
{


    char *str1 = "1234";
    int n1;
    n1 = atoi(str1);

    printf("%d\n",n1);


    return 0;

}




ex2)

 

1234e -> 1234

1234?123 -> 1234

1234? -> 1234

e1234 -> 0

?1234 -> 1234

qwer -> 0

?$% -> 0

 

---> 숫자가 아니면 0을 반환

'dev > C' 카테고리의 다른 글

[C] other - 1  (0) 2024.05.29
[C] 16진수를 문자열로 출력하기  (0) 2024.05.29
[C] function - strrchr()  (0) 2024.05.29
[C] function - strtok()  (0) 2024.05.29
[C] string - 4  (0) 2024.05.28