본문으로 바로가기
homeimage
  1. Home
  2. 컴퓨터/프로그래밍
  3. C언어 문자가 숫자 문자인( '0'~'9')지 판별 함수 isdigit()

C언어 문자가 숫자 문자인( '0'~'9')지 판별 함수 isdigit()

· 댓글개 · 바다야크

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)는 숫자 문자가 아닙니다.
]$
SNS 공유하기
💬 댓글 개
최근글
이모티콘창 닫기
울음
안녕
감사해요
당황
피폐

이모티콘을 클릭하면 댓글창에 입력됩니다.