int atoi(char* p) 함수를 구현하라.
작성자 : 김문규
최초 작성일 : 2008. 3 23
int convert_string_to_integer(char *_pchar)
{
char *pchar = _pchar;
int cnt = 0, value = 0, ispositive = 1;
if(pchar == NULL) return 0;
// check if the first character is '-' or not.
if( *pchar == '-' )
{
ispositive = -1;
pchar++;
}
while( (*pchar != '\0') && ('0' <= *pchar) && ('9' >= *pchar) )
{
value = value*10 + (int)*pchar-(int)'0';
*pchar++;
}
return ispositive*value;
}
'개발 노트' 카테고리의 다른 글
Internet Explorer 7 검색 공급자 주소 (0) | 2008.03.24 |
---|---|
성공하는 프로그래머들의 9가지 코딩 습관 (1) | 2008.03.23 |
Unix/Linux Redirection (0) | 2008.03.23 |
Linux에서 DNS Server 설정하기 (0) | 2008.03.23 |
CxxTest 사용법 (0) | 2008.03.23 |