-
Notifications
You must be signed in to change notification settings - Fork 0
isalnum
Marcos edited this page Oct 1, 2024
·
3 revisions
La función ft_isalnum comprueba si el carácter pasado como argumento es una letra del alfabeto (mayúscula o minúscula) o un dígito decimal. Es decir, evalúa si el carácter es alfanumérico.
ISALNUM(3) (simplified)
NAME
isalnum -- alphanumeric character test
SYNOPSIS
int isalnum(int c)
DESCRIPTION
The isalnum() function tests for any character for which isalpha(3) or isdigit(3) is true. The value of the argument must be representable as an unsigned char or the value of EOF.
RETURN VALUES
The isalnum() function returns zero if the character tests false and returns non-zero if the character tests true.
La función isalnum() evalúa si el valor entero pasado como argumento corresponde a un carácter alfabético (mayúscula o minúscula) o a un número decimal (de '0' a '9'). Si el valor es un carácter alfanumérico, la función devuelve un valor distinto de cero; de lo contrario, devuelve 0.
Aquí te muestro mi implementación de la función ft_isalnum en mi proyecto de Libft.
Código de ft_isalnum
int ft_isalnum(int c)
{
return ((c >= 65 && c <= 90)
|| (c >= 97 && c <= 122)
|| (c >= 48 && c <= 57));
}Aquí tienes el formato actualizado con los enlaces al código para la función ft_isalnum:
#include <stdio.h>
int ft_isalnum(int c);
int main(void)
{
char test1 = 'A';
char test2 = '9';
char test3 = '-';
printf("Test con 'A': %d\n", ft_isalnum(test1)); // Debe devolver 1
printf("Test con '9': %d\n", ft_isalnum(test2)); // Debe devolver 1
printf("Test con '-': %d\n", ft_isalnum(test3)); // Debe devolver 0
return 0;
}