aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-15 09:34:14 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-15 09:34:14 +0100
commite0f11e486518930e82e67f2dc305595671c074b5 (patch)
tree456a89d53c586317c1e3acdf759b1ca07ccd5550
parentd8e5d376244c6cf92e52666634cddaaf4e492aad (diff)
downloadlibft-e0f11e486518930e82e67f2dc305595671c074b5.tar.gz
libft-e0f11e486518930e82e67f2dc305595671c074b5.tar.bz2
libft-e0f11e486518930e82e67f2dc305595671c074b5.zip
Added ft_strcount
-rw-r--r--Makefile4
-rw-r--r--ft_strcount.c24
2 files changed, 26 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index f7caf07..b7ad478 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/11/05 22:16:32 by cacharle ### ########.fr #
+# Updated: 2019/11/15 09:19:31 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -28,7 +28,7 @@ SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.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_strndup.c \
- ft_strjoin_free.c ft_strjoin_free_snd.c get_next_line.c
+ ft_strjoin_free.c ft_strjoin_free_snd.c get_next_line.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..87e756d
--- /dev/null
+++ b/ft_strcount.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcount.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/15 09:17:48 by cacharle #+# #+# */
+/* Updated: 2019/11/15 09:19:36 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int ft_strcount(char *str, char c)
+{
+ int counter;
+
+ if (c == '\0')
+ return (1);
+ counter = 0;
+ while (*str)
+ if (*str++ == c)
+ counter++;
+ return (counter);
+}