first commit
This commit is contained in:
23
ended/C03/ex00/ft_strcmp.c
Normal file
23
ended/C03/ex00/ft_strcmp.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/20 16:55:23 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/20 16:55:30 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (s1[i] - s2[i]);
|
||||
}
|
27
ended/C03/ex01/ft_strncmp.c
Normal file
27
ended/C03/ex01/ft_strncmp.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/21 10:14:08 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/21 10:14:11 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strncmp(char *s1, char *s2, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
while (s1[i] == s2[i] && i + 1 < n && s1[i] != '\0' && s2[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (s1[i] - s2[i]);
|
||||
}
|
32
ended/C03/ex02/ft_strcat.c
Normal file
32
ended/C03/ex02/ft_strcat.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/21 15:08:59 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/21 15:11:10 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
|
||||
i = 0;
|
||||
l = 0;
|
||||
while (dest[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
while (src[l] != '\0')
|
||||
{
|
||||
dest[i] = src[l];
|
||||
i++;
|
||||
l++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
31
ended/C03/ex03/ft_strncat.c
Normal file
31
ended/C03/ex03/ft_strncat.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/22 09:49:37 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/22 09:49:45 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strncat(char *dest, char *src, unsigned int nb)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int l;
|
||||
|
||||
i = 0;
|
||||
l = 0;
|
||||
while (dest[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
while (src[l] != '\0' && l < nb)
|
||||
{
|
||||
dest[i + l] = src[l];
|
||||
l++;
|
||||
}
|
||||
dest[i + l] = '\0';
|
||||
return (dest);
|
||||
}
|
37
ended/C03/ex04/ft_strstr.c
Normal file
37
ended/C03/ex04/ft_strstr.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/25 10:18:22 by ajoly #+# #+# */
|
||||
/* Updated: 2022/07/25 10:18:26 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include <stddef.h>
|
||||
|
||||
char *ft_strstr(char *str, char *to_find)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *l[255];
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (str == 0)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == to_find[j])
|
||||
{
|
||||
str[j] = to_find[j];
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
l[i] = '\0';
|
||||
return (*str);
|
||||
}
|
Reference in New Issue
Block a user