--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isint.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/04/10 12:44:56 by ljiriste #+# #+# */
+/* Updated: 2024/04/10 13:17:33 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_check.h"
+#include "libft.h"
+#include <stdlib.h>
+
+// Checks whether str is a "pure" int
+// that is whether the string only contains digits
+// and whether it fits inside int
+int ft_isint(const char *str)
+{
+ const int num = ft_atoi(str);
+ char *newstr;
+ int sign;
+ int res;
+
+ sign = 1;
+ newstr = ft_itoa(num);
+ while (ft_isspace(*str))
+ ++str;
+ while (*str == '+' || *str == '-')
+ {
+ if (*str == '-')
+ sign *= -1;
+ ++str;
+ }
+ while (*str == '0')
+ ++str;
+ if (sign == -1)
+ res = !ft_strcmp(str, newstr + 1);
+ else
+ res = !ft_strcmp(str, newstr);
+ free(newstr);
+ return (res);
+}
/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/09 11:55:15 by ljiriste #+# #+# */
-/* Updated: 2023/12/09 15:13:41 by ljiriste ### ########.fr */
+/* Updated: 2024/04/10 12:54:40 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isspace(int c);
int ft_isupper(int c);
int ft_isascii(int c);
+int ft_isint(const char *str);
#endif