Add ft_strcmp function.
authorLukas Jiriste <ljiriste@student.42prague.com>
Sat, 13 Jan 2024 13:50:39 +0000 (14:50 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sat, 13 Jan 2024 13:50:39 +0000 (14:50 +0100)
Add ft_strcmp as it may be more ergonomic than ft_strncmp.
Add *.swp rule to .gitignore so that those won't bother me while vim is
opened.

.gitignore
ft_str/ft_strcmp.c [new file with mode: 0644]

index 33ac3dcd36e915c2f6e4db928fb57a676f4db93f..50498d85d2e517302bbd7c5f998ed6ee4067ef06 100644 (file)
@@ -1,2 +1,3 @@
 *.[ao]
+*.swp
 .libtemp
diff --git a/ft_str/ft_strcmp.c b/ft_str/ft_strcmp.c
new file mode 100644 (file)
index 0000000..279108c
--- /dev/null
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strcmp.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/13 14:11:31 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/13 14:48:37 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_str.h"
+#include <sys/types.h>
+
+int    ft_strcmp(const char *s1, const char *s2)
+{
+       size_t  i;
+
+       i = 0;
+       while (s1[i] == s2[i] && s1[i] && s2[i])
+               ++i;
+       if (n > 0)
+               return ((unsigned char)s1[i] - (unsigned char)s2[i]);
+       else
+               return (0);
+}