C isdigit() 문자가 ASCII 문자 인지 판별 함수
인수로 받은 문자가 숫자 문자인( '0'~'9')지를 판별합니다.
- 헤더: ctype.h
- 형태: int isdigit( int c)
- 인수: int c 판별할 문자
- 반환: int 0 != c는 숫자 문자, '0'~'9', 0 == c는 숫자 문자가 아님
C언어 isdigit() 함수 예제
#include <stdio.h>
#include <ctype.h>
int main( void)
{
int ch1 = '1';
int ch2 = 'a';
int ch3 = 256; // 아스키값 이상
if ( isdigit( ch1))
printf( "%c(x%03x)는 숫자 문자입니다.\n", ch1, ch1);
else
printf( "%c(x%03x)는 숫자 문자가 아닙니다.\n", ch1, ch1);
if ( isdigit( ch2))
printf( "%c(x%03x)는 숫자 문자입니다.\n", ch2, ch2);
else
printf( "%c(x%03x)는 숫자 문자가 아닙니다.\n", ch2, ch2);
if ( isdigit( ch3))
printf( "%c(x%03x)는 숫자 문자입니다.\n", ch3, ch3);
else
printf( "%c(x%03x)는 숫자 문자가 아닙니다.\n", ch3, ch3);
return 0;
}
C언어 isdigit() 예제 실행 결과
]$ ./a.out
1(x031)는 숫자 문자입니다.
a(x061)는 숫자 문자가 아닙니다.
(x100)는 숫자 문자가 아닙니다.
]$
'컴퓨터 > 프로그래밍' 카테고리의 다른 글
C언어 마이크로 초 동안 대기 함수 usleep() (0) | 2020.03.16 |
---|---|
C언어 문자가 제어문자인지 판별 함수 iscntrl() (0) | 2020.03.16 |
C언어 공백문자 또는 탭 문자인지 판별 함수 isblank() (0) | 2020.03.16 |