commit
This commit is contained in:
31
C_03/git/ex01/ft_strncmp.c
Normal file
31
C_03/git/ex01/ft_strncmp.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/12 15:16:07 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/18 11:35:55 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strncmp(char *s1, char *s2, unsigned int n)
|
||||
{
|
||||
char c1;
|
||||
char c2;
|
||||
|
||||
if (n == 0)
|
||||
return (0);
|
||||
c1 = '\0';
|
||||
c2 = '\0';
|
||||
while (n > 0)
|
||||
{
|
||||
c1 = *s1++;
|
||||
c2 = *s2++;
|
||||
if (c1 == '\0' || c1 != c2)
|
||||
break ;
|
||||
n--;
|
||||
}
|
||||
return (c1 - c2);
|
||||
}
|
||||
39
C_03/git/ex01/main.c
Normal file
39
C_03/git/ex01/main.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/12 15:16:20 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/12 15:16:21 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[32];
|
||||
char s2[32];
|
||||
unsigned int n;
|
||||
int result;
|
||||
|
||||
n = 0;
|
||||
printf("Input String #1 [max 31]: ");
|
||||
scanf("%s", s1);
|
||||
printf("Input String #2 [max 31]: ");
|
||||
scanf("%s", s2);
|
||||
printf("Input Number: ");
|
||||
scanf("%u", &n);
|
||||
result = ft_strncmp(s1, s2, n);
|
||||
printf("s1=%s s2=%s n=%d result=%d (ft_strncmp)\n", s1, s2, n, result);
|
||||
result = strncmp(s1, s2, n);
|
||||
printf("s1=%s s2=%s n=%d result=%d (strncmp)\n", s1, s2, n, result);
|
||||
return (0);
|
||||
}
|
||||
8
C_03/git/ex01/main.sh
Executable file
8
C_03/git/ex01/main.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
#norminette -R CheckForbiddenSourceHeader ft_*.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
|
||||
Reference in New Issue
Block a user