init
This commit is contained in:
23
Correction/levv/ex00/ft_strcpy.c
Normal file
23
Correction/levv/ex00/ft_strcpy.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/16 15:08:22 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/21 14:10:25 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strcpy(char *dest, char *src)
|
||||
{
|
||||
while (*src != '\0')
|
||||
{
|
||||
*dest = *src;
|
||||
src++;
|
||||
dest++;
|
||||
}
|
||||
*dest = '\0';
|
||||
return (dest);
|
||||
}
|
29
Correction/levv/ex01/ft_strncpy.c
Normal file
29
Correction/levv/ex01/ft_strncpy.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/16 15:08:22 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/21 14:13:36 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0' || i < n)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
while (i < n)
|
||||
{
|
||||
dest[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
24
Correction/levv/ex02/ft_str_is_alpha.c
Normal file
24
Correction/levv/ex02/ft_str_is_alpha.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_alpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 13:51:45 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/17 15:22:03 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_alpha(char *str)
|
||||
{
|
||||
while (*str != 0)
|
||||
{
|
||||
if (!(('a' <= *str && *str <= 'z') || ('A' <= *str && 'Z' >= *str)))
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
22
Correction/levv/ex03/ft_str_is_numeric.c
Normal file
22
Correction/levv/ex03/ft_str_is_numeric.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_numeric.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 15:29:04 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/18 08:43:44 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_numeric(char *str)
|
||||
{
|
||||
while (*str != 0)
|
||||
{
|
||||
if (!((*str >= '0') && (*str <= '9')))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
22
Correction/levv/ex04/ft_str_is_lowercase.c
Normal file
22
Correction/levv/ex04/ft_str_is_lowercase.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_lowercase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 13:51:45 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/18 08:36:27 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_lowercase(char *str)
|
||||
{
|
||||
while (*str != 0)
|
||||
{
|
||||
if (!('a' <= *str && *str <= 'z'))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
22
Correction/levv/ex05/ft_str_is_uppercase.c
Normal file
22
Correction/levv/ex05/ft_str_is_uppercase.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_uppercase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 10:46:58 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/18 10:47:05 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_uppercase(char *str)
|
||||
{
|
||||
while (*str != 0)
|
||||
{
|
||||
if (!('A' <= *str && *str <= 'Z'))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
22
Correction/levv/ex06/ft_str_is_printable.c
Normal file
22
Correction/levv/ex06/ft_str_is_printable.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_str_is_printable.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 08:36:39 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/18 08:36:41 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_str_is_printable(char *str)
|
||||
{
|
||||
while (*str != 0)
|
||||
{
|
||||
if (!(32 <= *str && *str <= 126))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
25
Correction/levv/ex07/ft_strupcase.c
Normal file
25
Correction/levv/ex07/ft_strupcase.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strupcase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 10:47:22 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/18 10:47:24 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strupcase(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if ('a' <= str[i] && str[i] <= 'z')
|
||||
str[i] = str[i] - 32;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
25
Correction/levv/ex08/ft_strlowcase.c
Normal file
25
Correction/levv/ex08/ft_strlowcase.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlowcase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 10:47:22 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/18 10:49:14 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strlowcase(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if ('A' <= str[i] && str[i] <= 'Z')
|
||||
str[i] = str[i] + 32;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
BIN
Correction/levv/ex09/a.out
Executable file
BIN
Correction/levv/ex09/a.out
Executable file
Binary file not shown.
68
Correction/levv/ex09/ft_strcapitalize.c
Normal file
68
Correction/levv/ex09/ft_strcapitalize.c
Normal file
@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcapitalize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 10:52:54 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/21 18:16:57 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_lower(char c)
|
||||
{
|
||||
if ('a' <= c && c <= 'z')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_is_upper(char c)
|
||||
{
|
||||
if ('A' <= c && c <= 'Z')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_is_alpha(char c)
|
||||
{
|
||||
if (ft_is_lower(c) || ft_is_upper(c))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_is_digit(char c)
|
||||
{
|
||||
if ('0' <= c && c <= '9')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *ft_strcapitalize(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
if (ft_is_lower(str[0]))
|
||||
str[i] -= 32;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if (!(ft_is_alpha(str[i - 1]) || ft_is_digit(str[i - 1])))
|
||||
{
|
||||
if (ft_is_lower(str[i]))
|
||||
str[i] -= 32;
|
||||
}
|
||||
else
|
||||
if (ft_is_upper(str[i]))
|
||||
str[i] += 32;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
int main(void)
|
||||
{
|
||||
char str[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un";
|
||||
printf("%s",ft_strcapitalize(str));
|
||||
}
|
BIN
Correction/levv/ex10/a.out
Executable file
BIN
Correction/levv/ex10/a.out
Executable file
Binary file not shown.
39
Correction/levv/ex10/ft_strlcpy.c
Normal file
39
Correction/levv/ex10/ft_strlcpy.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/21 14:13:53 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/21 18:25:55 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlcpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0' && dest[i] != '\0' && i < n)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
while (i < n && dest[i] != '\0')
|
||||
{
|
||||
dest[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include <bsd/string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char src[42] = "jetest";
|
||||
char dest[42];
|
||||
printf("%d\n", ft_strlcpy(dest, src, 4));
|
||||
printf("%ld", strlcpy(dest, src, 4));
|
||||
}
|
Reference in New Issue
Block a user