From a49d88af64b6eab068b559057eda40cf0eb52281 Mon Sep 17 00:00:00 2001 From: Guy Baconniere Date: Wed, 18 Aug 2021 14:08:59 +0200 Subject: [PATCH] sync --- C_Piscine_C_03/git/ex01/ft_strncmp.copy.c | 27 ++++++++++++++ C_Piscine_C_03/git/ex01/t.c | 37 ++++++++++++++++++++ C_Piscine_C_03/git/ex01/t.sh | 7 ++++ C_Piscine_C_05/git/ex07/ft_find_next_prime.c | 4 +-- 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 C_Piscine_C_03/git/ex01/ft_strncmp.copy.c create mode 100644 C_Piscine_C_03/git/ex01/t.c create mode 100755 C_Piscine_C_03/git/ex01/t.sh diff --git a/C_Piscine_C_03/git/ex01/ft_strncmp.copy.c b/C_Piscine_C_03/git/ex01/ft_strncmp.copy.c new file mode 100644 index 0000000..7d1f7ba --- /dev/null +++ b/C_Piscine_C_03/git/ex01/ft_strncmp.copy.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dgloriod +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/09 11:32:49 by dgloriod #+# #+# */ +/* Updated: 2021/08/18 11:44:44 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + unsigned int i; + + i = 0; + while (i < n) + { + if (s1[i] > s2[i]) + return (1); + else if (s1[i] < s2[i]) + return (-1); + i++; + } + return (0); +} diff --git a/C_Piscine_C_03/git/ex01/t.c b/C_Piscine_C_03/git/ex01/t.c new file mode 100644 index 0000000..0930299 --- /dev/null +++ b/C_Piscine_C_03/git/ex01/t.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/12 15:16:20 by gbaconni #+# #+# */ +/* Updated: 2021/08/18 12:00:04 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +int ft_strncmp(char *s1, char *s2, unsigned int n); + +int main(void) +{ + char *s1 = "a"; + char *s2 = "a"; + unsigned int n = 65536; + int result; + + while (n < 80000) + { + printf("[%d]:\n", n); + result = strncmp(s1, s2, n); + printf("s1=%s s2=%s n=%d result=%d (strncmp)\n", s1, s2, n, result); + result = ft_strncmp(s1, s2, n); + printf("s1=%s s2=%s n=%d result=%d (ft_strncmp)\n", s1, s2, n, result); + n++; + } + return (0); +} diff --git a/C_Piscine_C_03/git/ex01/t.sh b/C_Piscine_C_03/git/ex01/t.sh new file mode 100755 index 0000000..2913b5e --- /dev/null +++ b/C_Piscine_C_03/git/ex01/t.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +norminette -R CheckForbiddenSourceHeader ft_strncmp.copy.c +gcc -Wall -Wextra -Werror -o a.out ft_strncmp.copy.c t.c +echo $(basename $PWD): +./a.out +rm -f a.out diff --git a/C_Piscine_C_05/git/ex07/ft_find_next_prime.c b/C_Piscine_C_05/git/ex07/ft_find_next_prime.c index 7ec19a6..e59dc22 100644 --- a/C_Piscine_C_05/git/ex07/ft_find_next_prime.c +++ b/C_Piscine_C_05/git/ex07/ft_find_next_prime.c @@ -6,7 +6,7 @@ /* By: gbaconni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/08/18 10:53:52 by gbaconni #+# #+# */ -/* Updated: 2021/08/18 12:12:03 by gbaconni ### ########.fr */ +/* Updated: 2021/08/18 14:03:38 by gbaconni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int ft_find_next_prime(int nb) r = 0; while (r == 0) { - if (nb == 0 || nb == 1) + if (nb <= 0 || nb == 1) r = 0; else r = 1;