0
0
This commit is contained in:
Guy Baconniere
2021-08-18 13:05:29 +02:00
parent 74e3cc8eb8
commit df07d7f9f7
21 changed files with 141 additions and 53 deletions

View File

@@ -6,7 +6,7 @@
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 15:16:07 by gbaconni #+# #+# */
/* Updated: 2021/08/12 15:16:11 by gbaconni ### ########.fr */
/* Updated: 2021/08/18 11:35:55 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgloriod <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@@ -1,8 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
norminette -R CheckForbiddenSourceHeader ft_strncmp.c
gcc -Wall -Wextra -Werror -o a.out ft_strncmp.c main.c
echo $(basename $PWD):
./a.out
rm -f a.out

View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 15:16:20 by gbaconni #+# #+# */
/* Updated: 2021/08/18 12:00:04 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
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);
}

7
C_Piscine_C_03/git/ex01/t.sh Executable file
View File

@@ -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