➰ 코딩 부트캠프/42 seoul

[0 Circle] Libft - ft_isalpha, ft_isdigit, ft_isalnum, ft_isascii, ft_isprint, ft_toupper, ft_tolower

 사과개발자 2021. 1. 4. 22:02

📌ft_isalpha

문자하나가 알파벳이면 1, 아니면 0

➕ 코드 (Code)

#include "libft.h"

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

📌ft_isdigit

문자하나가 숫자이면 1, 아니면 0

➕ 코드 (Code)

#include "libft.h"

int        ft_isdigit(int c)
{
    return (c >= '0' && c <= '9');
}

📌ft_isalnum

문자하나가 알파벳이거나 숫자이면 1, 아니면 0

➕ 코드 (Code)

#include "libft.h"

int        ft_isalnum(int c)
{
    if (c >= 'a' && c <= 'z')
        return (1);
    if (c >= 'A' && c <= 'Z')
        return (1);
    if (c >= '0' && c <= '9')
        return (1);
    return (0);
}

📌ft_isascii

문자하나가 아스키코드이면 1, 아니면 0

➕ 코드 (Code)

#include "libft.h"

int        ft_isascii(int c)
{
    return (c >= 0 && c <= 127);
}

📌ft_isprint

문자하나가 printable이면 1, 아니면 0

➕ 코드 (Code)

#include "libft.h"

int        ft_isprint(int c)
{
    return (c >= 32 && c <= 126);
}

📌ft_toupper

문자하나가 소문자이면 대문자

➕ 코드 (Code)

#include "libft.h"

int        ft_toupper(int c)
{
    if (c >= 'a' && c <= 'z')
        c -= ('a' - 'A');
    return (c);
}

📌ft_tolower

문자하나가 대문자이면 소문자

➕ 코드 (Code)

#include "libft.h"

int        ft_tolower(int c)
{
    if (c >= 'A' && c <= 'Z')
        c += ('a' - 'A');
    return (c);
}
반응형