aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--ft_strcount.c24
-rw-r--r--libft.h3
3 files changed, 28 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 6758101..392b40c 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/08 15:45:53 by cacharle #+# #+# #
-# Updated: 2019/10/17 13:39:09 by cacharle ### ########.fr #
+# Updated: 2020/01/16 07:45:42 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -25,7 +25,7 @@ SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c f
ft_striteri.c ft_strjoin.c ft_strlcat.c ft_strlen.c ft_strmap.c ft_strmapi.c \
ft_strncat.c ft_strncmp.c ft_strncpy.c ft_strnequ.c ft_strnew.c ft_strnstr.c \
ft_strrchr.c ft_split.c ft_strstr.c ft_substr.c ft_strtrim.c ft_tolower.c \
- ft_toupper.c ft_strlcpy.c ft_calloc.c
+ ft_toupper.c ft_strlcpy.c ft_calloc.c ft_strcount.c
OBJ = $(SRC:.c=.o)
INCLUDE = libft.h
diff --git a/ft_strcount.c b/ft_strcount.c
new file mode 100644
index 0000000..87ead29
--- /dev/null
+++ b/ft_strcount.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcount.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/15 14:45:33 by cacharle #+# #+# */
+/* Updated: 2020/01/16 07:45:32 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int ft_strcount(char *str, char c)
+{
+ int counter;
+
+ if (c == '\0')
+ return (0);
+ counter = 0;
+ while (*str)
+ if (*str++ == c)
+ counter++;
+ return (counter);
+}
diff --git a/libft.h b/libft.h
index 87b57c2..6e767fd 100644
--- a/libft.h
+++ b/libft.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */
-/* Updated: 2019/10/17 09:08:31 by cacharle ### ########.fr */
+/* Updated: 2020/01/15 14:46:50 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -48,6 +48,7 @@ char *ft_strnstr(const char *haystack,
const char *needle, size_t len);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
+int ft_strcount(char *str, char c);
int ft_atoi(const char *nptr);
int ft_isalpha(int c);
int ft_isdigit(int c);