Compare commits

...

7 Commits

Author SHA1 Message Date
Timo Schmidt dc014441bc ALL 2023-03-21 07:28:41 +01:00
Timo Schmidt e0eeb8dee5 ft_strncpy.c 2023-03-19 18:05:17 +01:00
Timo Schmidt 8d8799c509 ft_strlcpy.c 2023-03-19 11:59:24 +01:00
Timo Schmidt ea50fc0232 ft_strcapitalize.c 2023-03-19 11:48:21 +01:00
Timo Schmidt c41701f2d9 ft_strcapitalize.c 2023-03-19 11:44:47 +01:00
Timo Schmidt 7d4fe515b9 ft_strlowcase.c 2023-03-19 11:27:14 +01:00
Timo Schmidt cd2f992fbd ft_strupcase.c 2023-03-19 11:25:30 +01:00
7 changed files with 251 additions and 5 deletions

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 10:25:26 by tischmid #+# #+# */
/* Updated: 2023/03/19 10:33:04 by tischmid ### ########.fr */
/* Updated: 2023/03/19 18:05:09 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,13 +16,9 @@ char *ft_strncpy(char *dest, char *src, unsigned int n)
i = -1;
while (++i < n && src[i] != '\0')
{
dest[i] = src[i];
}
while (++i < n)
{
dest[i] = '\0';
}
return (dest);
}

36
ex07/ft_strupcase.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strupcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:18:13 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:25:38 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strupcase(char *str)
{
int i;
i = -1;
while (str[++i] != '\0')
if (str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] & 95;
return (str);
}
/* ////
#include <stdio.h>
int main(void)
{
char s1[] = "hello world";
char *s2;
printf("%s\n", s1);
s2 = ft_strupcase(s1);
printf("%s\n", s2);
return (0);
}
*/ ////

36
ex08/ft_strlowcase.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlowcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:18:13 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:27:10 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strlowcase(char *str)
{
int i;
i = -1;
while (str[++i] != '\0')
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] | 32;
return (str);
}
/* ////
#include <stdio.h>
int main(void)
{
char s1[] = "hEllO worLd";
char *s2;
printf("%s\n", s1);
s2 = ft_strlowcase(s1);
printf("%s\n", s2);
return (0);
}
*/ ////

53
ex09/ft_strcapitalize.c Normal file
View File

@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:27:43 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:48:58 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcapitalize(char *str)
{
int i;
int inside_word;
int is_alpha;
int is_numeric;
char c;
inside_word = 0;
i = -1;
while (str[++i] != '\0')
{
c = str[i];
is_alpha = ((c | 32) >= 'a' && (c | 32) <= 'z');
is_numeric = (c >= '0' && c <= '9');
if (!inside_word && (is_alpha || is_numeric))
{
inside_word = 1;
if (is_alpha)
str[i] = str[i] & 95;
}
else if (inside_word && (is_alpha || is_numeric))
str[i] = str[i] | 32;
else
inside_word = 0;
}
return (str);
}
/* ////
#include <stdio.h>
int main(void)
{
char s1[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un";
char *s2;
s2 = ft_strcapitalize(s1);
printf("%s\n", s2);
return (0);
}
*/ ////

36
ex10/ft_strlcpy.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:49:46 by tischmid #+# #+# */
/* Updated: 2023/03/21 00:48:06 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
{
unsigned int i;
i = -1;
while (*src && ++i < size - 1)
*dest++ = *src++;
*dest = 0;
return (i);
}
/* ////
#include <stdio.h>
int main(void)
{
char buf[BUFSIZ];
char str[] = {'A','B','C','D','E','\0'};
ft_strlcpy(buf, str, 5);
printf("%s\n", buf);
return (0);
}
*/ ////

View File

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_non_printable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 02:59:50 by tischmid #+# #+# */
/* Updated: 2023/03/21 03:10:35 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr_non_printable(char *str)
{
char first_digit;
char second_digit;
while (*str)
{
if (*str < 32)
{
first_digit = "0123456789abcdef"[*str / 16];
second_digit = "0123456789abcdef"[*str % 16];
write(1, "\\", 1);
write(1, &first_digit, 1);
write(1, &second_digit, 1);
}
else
{
write(1, str, 1);
}
++str;
}
}
/* ////
#include <stdio.h>
int main(void)
{
char s1[200];
int i;
for (i = 0; i < 127; ++i)
{
s1[i] = i + 1;
}
s1[i] = 0;
ft_putstr_non_printable(s1);
return (0);
}
*/ ////

35
ex12/ft_print_memory.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_memory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 05:44:01 by tischmid #+# #+# */
/* Updated: 2023/03/21 06:43:18 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void *ft_print_memory(void *addr, unsigned int size)
{
return (addr);
}
/* ////
#include <stdio.h>
int main(void)
{
char s[] = "0123456789abcdef0123456789abcdefghijklmnopqrstuvwxyz";
ft_print_memory(s, 20);
return (0);
}
*/ ////