Compare commits

...

10 Commits

12 changed files with 131 additions and 104 deletions

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 05:59:56 by tischmid #+# #+# */
/* Updated: 2023/03/19 06:04:51 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:29:58 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,13 +23,22 @@ char *ft_strcpy(char *s1, char *s2)
/* ////
#include <stdio.h>
#define BUFSIZE 10
#define STR "||||||||||"
int main(void)
{
char s1[10];
int arrlen = 4;
char *teststrings[] = {"", "h", "he", "hey"};
char buf[BUFSIZE] = STR;
ft_strcpy(s1, "0123456789");
printf("%s\n", s1);
for (int j = 0; j < arrlen; ++j)
{
printf("####### Element == '%s' #######\n", teststrings[j]);
ft_strcpy(buf, teststrings[j]);
for (int i = 0; i < BUFSIZE; ++i)
printf((buf[i] >= 32 && buf[i] <= 126) ? "%c\n" : "0x%x\n", buf[i]);
}
return (0);
}
*/ ////

View File

@ -6,31 +6,36 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 10:25:26 by tischmid #+# #+# */
/* Updated: 2023/03/19 18:05:09 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:29:37 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = -1;
while (++i < n && src[i] != '\0')
dest[i] = src[i];
while (++i < n)
dest[i] = '\0';
++n;
while (--n && *src)
*dest++ = *src++;
while (n--)
*dest++ = 0;
return (dest);
}
/* ////
#include <stdio.h>
#define BUFSIZE 10
#define STR "||||||||||"
int main(void)
{
char s1[10];
char buf[BUFSIZE] = STR;
ft_strncpy(s1, "Hello", 4);
printf("%s\n", s1);
for (int j = 0; j < 11; ++j)
{
printf("####### Size == %d #######\n", j);
ft_strncpy(buf, "Hei", j);
for (int i = 0; i < BUFSIZE; ++i)
printf((buf[i] >= 32 && buf[i] <= 126) ? "%c\n" : "0x%x\n", buf[i]);
}
return (0);
}
*/ ////

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 10:33:26 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:04:39 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:29:19 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,11 +24,14 @@ int ft_str_is_alpha(char *str)
/* ////
#include <stdio.h>
#define STR "aa"
int main(void)
{
char s[] = "";
printf("%d\n", ft_str_is_alpha(s));
if (ft_str_is_alpha(STR))
printf("Contains only alphabetical characters\n");
else
printf("Contains non-alphabetical characters\n");
return (0);
}
*/ ////

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 10:33:26 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:04:24 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:29:01 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,11 +24,14 @@ int ft_str_is_numeric(char *str)
/* ////
#include <stdio.h>
#define STR "0123456789"
int main(void)
{
char s[] = "";
printf("%d\n", ft_str_is_numeric(s));
if (ft_str_is_numeric(STR))
printf("Is numeric\n");
else
printf("Is not numeric\n");
return (0);
}
*/ ////

View File

@ -6,29 +6,27 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:03:56 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:17:16 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:08:55 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_lowercase(char *str)
{
int i;
i = 0;
while (str[i] >= 'a' && str[i] <= 'z')
{
++i;
}
return (str[i] == '\0');
while (*str >= 'a' && *str <= 'z')
++str;
return (!*str);
}
/* ////
#include <stdio.h>
#define STR "abcd"
int main(void)
{
char s[] = "abcdef";
printf("%d\n", ft_str_is_lowercase(s));
if (ft_str_is_lowercase(STR))
printf("Is all lowercase\n");
else
printf("Contains non-lowercase characters\n");
return (0);
}
*/ ////

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:03:56 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:17:00 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:16:08 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,11 +24,14 @@ int ft_str_is_uppercase(char *str)
/* ////
#include <stdio.h>
#define STR "ABCDEf"
int main(void)
{
char s[] = "ABCDEF";
printf("%d\n", ft_str_is_uppercase(s));
if (ft_str_is_uppercase(STR))
printf("Is all uppercase\n");
else
printf("Contains non-uppercase characters\n");
return (0);
}
*/ ////

View File

@ -6,7 +6,7 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:03:56 by tischmid #+# #+# */
/* Updated: 2023/03/22 20:27:43 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:16:50 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,11 +24,14 @@ int ft_str_is_printable(char *str)
/* ////
#include <stdio.h>
#define STR "BCDEF ~~~ "
int main(void)
{
char s[] = "A BCDEF ~~~ ";
printf("%d\n", ft_str_is_printable(s));
if (ft_str_is_printable(STR))
printf("Is printable\n");
else
printf("Is not printable\n");
return (0);
}
*/ ////

View File

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

View File

@ -6,31 +6,33 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:18:13 by tischmid #+# #+# */
/* Updated: 2023/03/21 09:33:54 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:28:12 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strlowcase(char *str)
{
int i;
char *orig_str;
i = -1;
while (str[++i] != '\0')
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] | 32;
return (str);
orig_str = str;
while (*str)
{
if (*str >= 'A' && *str <= 'Z')
*str |= 32;
++str;
}
return (orig_str);
}
/* ////
#include <stdio.h>
#define STR "hEllO worLd"
int main(void)
{
char s1[] = "hEllO worLd";
char *s2;
char s1[] = STR;
printf("%s\n", s1);
s2 = ft_strlowcase(s1);
printf("%s\n", s2);
printf("%s\n", ft_strlowcase(s1));
return (0);
}
*/ ////

View File

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

View File

@ -6,19 +6,24 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:49:46 by tischmid #+# #+# */
/* Updated: 2023/03/21 09:44:10 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:30:43 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#define BUFSIZE 10
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
{
unsigned int i;
char *orig_src;
i = -1;
while (*src && ++i < size - 1)
orig_src = src;
while (size-- > 1 && *src)
*dest++ = *src++;
*dest = 0;
return (i);
size = 0;
while (*orig_src++)
++size;
return (size);
}
/* ////
@ -26,15 +31,17 @@ unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
int main(void)
{
char buf2[10];
char buf[2];
char str[] = {'A','B','C','D','E','\0'};
char buf[BUFSIZE] = "||||||||||";
unsigned int return_size;
ft_strlcpy(buf, str, 6);
printf("%p\n", buf);
printf("%s\n", buf);
printf("%p\n", buf2);
printf("%s\n", buf2);
for (int j = 0; j < 11; ++j)
{
printf("####### Size == %d #######\n", j);
return_size = ft_strlcpy(buf, "01234", j);
printf("Return Size: %d\n", return_size);
for (int i = 0; i < BUFSIZE; ++i)
printf((buf[i] >= 32 && buf[i] <= 126) ? "%c\n" : "0x%x\n", buf[i]);
}
return (0);
}
*/ ////

View File

@ -6,48 +6,41 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 02:59:50 by tischmid #+# #+# */
/* Updated: 2023/03/21 03:10:35 by tischmid ### ########.fr */
/* Updated: 2023/03/24 01:04:50 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#define HEX_ALPH "0123456789abcdef"
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);
write(1, &HEX_ALPH[*(unsigned char *) str / 16], 1);
write(1, &HEX_ALPH[*(unsigned char *) str % 16], 1);
}
else
{
write(1, str, 1);
}
++str;
}
}
/* ////
#include <stdio.h>
#define BUFSIZE 256
int main(void)
{
char s1[200];
int i;
char s1[BUFSIZE];
for (i = 0; i < 127; ++i)
for (int i = -128; i < 127; ++i)
{
s1[i] = i + 1;
s1[i + 128] = i ? i : 1;
}
s1[i] = 0;
ft_putstr_non_printable(s1);
return (0);
}