문자 입력을 분석하고 변환하기 위해 "ctype.h" 라이브러리에서 사용할 수 있는 몇 가지 미리 정의된 함수가 있습니다.
분석 기능
캐릭터 분석 기능은 아래와 같습니다 -
| 함수 | 입력한 문자가 맞는지 확인 |
|---|---|
| 이알파 | 알파벳(또는) 아님 |
| 숫자 | 숫자(또는) 아님 |
| isspace Q | 공백, 줄 바꿈(또는) 탭 |
| 명확한 ( | 특수 기호(또는) 아님 |
| 낮음 | 알파벳의 소문자 |
| 저녁식사 Q | 알파벳의 대문자 |
| 영숫자 | 알파벳/숫자 여부 |
변환 기능
변환 기능은 다음과 같습니다 -
| 함수 | 전환 |
|---|---|
| tolower() | 대문자를 소문자로 변환 |
| 토퍼 Q | 소문자 알파벳을 대문자로 변환 |
프로그램
다음은 문자 유형을 테스트하는 데 사용되는 문자 분석 및 변환 기능을 위한 C 프로그램입니다 -
#include <stdio.h>
#include <ctype.h>
main(){
char character;
printf("Press any key digit or alphabet\n");
character = getchar();
if (isalpha(character) > 0)
printf("The character is a letter.");
else
if (isdigit (character) > 0)
printf("The character is a digit.");
else
printf("The character is not alphanumeric.");
} 출력
위의 프로그램을 실행하면 다음과 같은 결과가 나온다 -
Run 1: Press any key digit or alphabet 3 The character is a digit. Run 2: Press any key digit or alphabet G The character is a letter. Run 3: Press any key digit or alphabet & The character is not alphanumeric.