
📌 매뉴얼 (Linux)
SYNOPSIS
int isdigit(int c);
: 함수 프로토타입
DESCRIPTION
isdigit()
checks for a digit (0 through 9).
: 0 ~ 9 까지의 10진수인지 확인
RETURN VALUE
The values returned are nonzero if the character c falls into the tested class, and zero if
not.
: 반환값은 조건에 만족하지 않으면 0이고, 만족하면 0이 아닌 값이다
NOTES
The standards require that the argument c for these functions is either EOF or a value that is
representable in the type unsigned char. If the argument c is of type char, it must be cast
to unsigned char, as in the following example:
char c;
...
res = toupper((unsigned char) c);
This is necessary because char may be the equivalent of signed char, in which case a byte
where the top bit is set would be sign extended when converting to int, yielding a value that
is outside the range of unsigned char.
The details of what characters belong to which class depend on the locale. For example, isup‐
per() will not recognize an A-umlaut (Ä) as an uppercase letter in the default C locale.
📌 작성 코드
int do_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
else
return (0);
}
📌 코드 리뷰
역시나 단순하게 '0' 부터 '9' 까지 if문으로 조건을 줬는데,
따옴표 없이 int형 0 ~ 9가 아니라 문자 자료형으로 주어진 것을 함수로 판별하기 때문에
'0' (= 48), '9' (= 57) 로 적용해야 해당 문자가 digit인지 판단하는 함수가 되는 걸 유의해야한다.
'프로그래밍 > C' 카테고리의 다른 글
[library] isalnum 구현하기 (0) | 2024.03.13 |
---|---|
[study] 구조체 & 구조체 포인터 (0) | 2024.03.13 |
[study] file descriptor 와 open() (0) | 2024.03.12 |
[study] 함수 포인터 (1) | 2024.03.11 |
[library] isalpha 구현하기 (0) | 2024.02.29 |