본문 바로가기

프로그래밍/C

[library] isascii 구현하기

📌 매뉴얼 (Linux)

더보기

SYNOPSIS

       int isascii(int c);

: 함수 프로토타입

 

DESCRIPTION

       isascii()
              checks whether c is a 7-bit unsigned char value that fits into the ASCII character set.

: c가 ASCII 문자 집합에 맞는 7 bit (부호가 없는) 문자 값인지 확인한다

 

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_isascii(int d)
{
	if (d >= 0 && d <= 127)
		return (1);
	else
		return (0);
}

 

📌 코드 리뷰

매뉴얼에서 7bit unsigned 로 범위를 설정해주어서, 0 ~ 127 까지의 값을 나타낸다는 것을 알수 있다. (2^7 = 128)

해당 범위 내에 있으면 ASCII 문자표에 있는 문자들을 모두 확인할 수 있고 이 문자에 해당하면 1을 반환, 아니면 0을 반환한다.

확장 아스키코드는 따로 isascii로 확인하지 않는 것을 알 수 있다.

'프로그래밍 > C' 카테고리의 다른 글

[library] strlen 구현하기  (0) 2024.03.18
[library] isprint 구현하기  (0) 2024.03.18
[study] Linked List (연결 리스트)  (0) 2024.03.14
[library] isalnum 구현하기  (0) 2024.03.13
[study] 구조체 & 구조체 포인터  (0) 2024.03.13
Recent Posts
Popular Posts
Recent Comments