-
Notifications
You must be signed in to change notification settings - Fork 0
isdigit
Marcos edited this page Oct 1, 2024
·
2 revisions
La función ft_isdigit comprueba si el carácter pasado como argumento es un dígito decimal, es decir, si corresponde a un número del 0 al 9.
ISDIGIT(3) (simplified)
NAME
isdigit -- decimal-digit character test
SYNOPSIS
int isdigit(int c)
DESCRIPTION
The isdigit() function tests for a decimal digit character.
The value of the argument must be representable as an unsigned char or the value of EOF.
RETURN VALUES
The isdigit() function return zero if the character tests false and return non-zero if the character tests true.
La función isdigit() evalúa si el valor entero pasado como argumento corresponde a un carácter que representa un dígito decimal (es decir, un número del '0' al '9'). Si el valor es un carácter numé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_isdigit en mi proyecto de Libft.
Código de ft_isdigit
int ft_isdigit(int c)
{
return (c >= 48 && c <= 57);
}El siguiente código es un ejemplo de cómo puedes probar la función.
#include <stdio.h>
int ft_isdigit(int c);
int main(void)
{
char test1 = '0';
char test2 = '9';
char test3 = 'A';
printf("Test con '0': %d\n", ft_isdigit(test1)); // Debe devolver 1
printf("Test con '9': %d\n", ft_isdigit(test2)); // Debe devolver 1
printf("Test con 'A': %d\n", ft_isdigit(test3)); // Debe devolver 0
return 0;
}