isalpha

유제민·2025년 4월 9일

42경산

목록 보기
2/17

isalpha가 뭐예요..ㅎㅎ..ㅋㅋ..;;

isaplha 함수란 주어진 매개변수가 알파벳인가를 알 수 있게 해주는 함수이다.
주어진 매개변수가 ascii 상으로 'a'보다 크거나 같고, 'z'보다 작거나 같은지, 아니면 'A보다 크거나 같고, 'Z'보다 작거나 같다면 1을 리턴해주고 조건에 충족하지 못하다면 0을 리턴해주면 된다.

ascii 상으로 65보다 크거나 같고 90보다 작거나 같거나, 97보다 크거나 같고, 122보다 작거나 같다면 1을 리턴

ft_isalpha 구현

#include "libft.h"

int	ft_isalpha(int c)
{
	if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'z'))
    	return (1);
    else
    	return (0);
}

isalpha_testcase 구현

#include "libft.h"
#include <stdio.h>
#include <ctype.h>

void	main(void)
{	
	//대문자 'A'
	printf("[ %c ] ft_isalpha(%d) : %d\n", 65, 65, isalpha(65));
	//대문자 'C'
	printf("[ %c ] ft_isalpha(%d) : %d\n", 67, 67, isalpha(67));
	//소문자 'a'
	printf("[ %c ] ft_isalpha(%d) : %d\n", 97, 97, isalpha(97));
	//소문자 'c'
	printf("[ %c ] ft_isalpha(%d) : %d\n", 99, 99, isalpha(99));
	//숫자 '0'
	printf("[ %c ] ft_isalpha(%d) : %d\n", 48, 48, isalpha(48));
	//숫자 '2'
	printf("[ %c ] ft_isalpha(%d) : %d\n", 50, 50, isalpha(50));
}
profile
무진장 게으른

0개의 댓글