piscine/c03/ex00/ft_strcmp.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

44 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/07 14:39:41 by whaffman #+# #+# */
/* Updated: 2024/06/10 15:50:16 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <string.h>
int ft_strcmp(char *s1, char *s2)
{
while (*s1 && *s1 == *s2)
{
s1++;
s2++;
}
return (*s1 - *s2);
}
#ifdef DEBUG
void test(char *s1, char *s2)
{
printf("s1: \"%s\"\ns2: \"%s\"\nft_strcmp: %d\nstrcmp: %d\n", \
s1, s2, ft_strcmp(s1, s2), strcmp(s1, s2));
}
int main(void)
{
test("abc", "abc");
test("ab", "abc");
test("abc", "ab");
test("abd", "abc");
test("abc", "abd");
return (0);
}
#endif