From baae62458943a22c787b20a771574c6d94f5eca7 Mon Sep 17 00:00:00 2001 From: Timo Schmidt Date: Fri, 24 Mar 2023 01:30:20 +0100 Subject: [PATCH] Too much --- ex00/ft_strcpy.c | 16 ++++++++++++---- ex01/ft_strncpy.c | 6 +++--- ex02/ft_str_is_alpha.c | 9 ++++++--- ex03/ft_str_is_numeric.c | 9 ++++++--- ex04/ft_str_is_lowercase.c | 20 +++++++++----------- ex05/ft_str_is_uppercase.c | 9 ++++++--- ex06/ft_str_is_printable.c | 9 ++++++--- ex07/ft_strupcase.c | 5 +++-- ex08/ft_strlowcase.c | 5 +++-- ex09/ft_strcapitalize.c | 30 ++++++++++++++---------------- ex11/ft_putstr_non_printable.c | 23 ++++++++--------------- 11 files changed, 76 insertions(+), 65 deletions(-) diff --git a/ex00/ft_strcpy.c b/ex00/ft_strcpy.c index 85881e7..921099a 100644 --- a/ex00/ft_strcpy.c +++ b/ex00/ft_strcpy.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/19 05:59:56 by tischmid #+# #+# */ -/* Updated: 2023/03/24 01:05:46 by tischmid ### ########.fr */ +/* Updated: 2023/03/24 01:29:58 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,13 +24,21 @@ char *ft_strcpy(char *s1, char *s2) /* //// #include #define BUFSIZE 10 +#define STR "||||||||||" int main(void) { - char s1[BUFSIZE]; + 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); } */ //// diff --git a/ex01/ft_strncpy.c b/ex01/ft_strncpy.c index 2e07184..9c264cb 100644 --- a/ex01/ft_strncpy.c +++ b/ex01/ft_strncpy.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/19 10:25:26 by tischmid #+# #+# */ -/* Updated: 2023/03/24 01:05:10 by tischmid ### ########.fr */ +/* Updated: 2023/03/24 01:29:37 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,11 +23,11 @@ char *ft_strncpy(char *dest, char *src, unsigned int n) /* //// #include #define BUFSIZE 10 - +#define STR "||||||||||" int main(void) { - char buf[BUFSIZE] = "||||||||||"; + char buf[BUFSIZE] = STR; for (int j = 0; j < 11; ++j) { diff --git a/ex02/ft_str_is_alpha.c b/ex02/ft_str_is_alpha.c index 140610c..cb8495d 100644 --- a/ex02/ft_str_is_alpha.c +++ b/ex02/ft_str_is_alpha.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#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); } */ //// diff --git a/ex03/ft_str_is_numeric.c b/ex03/ft_str_is_numeric.c index 623777e..6616bc0 100644 --- a/ex03/ft_str_is_numeric.c +++ b/ex03/ft_str_is_numeric.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#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); } */ //// diff --git a/ex04/ft_str_is_lowercase.c b/ex04/ft_str_is_lowercase.c index 2f497fc..64b4c56 100644 --- a/ex04/ft_str_is_lowercase.c +++ b/ex04/ft_str_is_lowercase.c @@ -6,29 +6,27 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#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); } */ //// diff --git a/ex05/ft_str_is_uppercase.c b/ex05/ft_str_is_uppercase.c index e397148..f9b6801 100644 --- a/ex05/ft_str_is_uppercase.c +++ b/ex05/ft_str_is_uppercase.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#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); } */ //// diff --git a/ex06/ft_str_is_printable.c b/ex06/ft_str_is_printable.c index 9c15e4e..bef1583 100644 --- a/ex06/ft_str_is_printable.c +++ b/ex06/ft_str_is_printable.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#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); } */ //// diff --git a/ex07/ft_strupcase.c b/ex07/ft_strupcase.c index 52c2c6c..5e51a0d 100644 --- a/ex07/ft_strupcase.c +++ b/ex07/ft_strupcase.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/19 11:18:13 by tischmid #+# #+# */ -/* Updated: 2023/03/24 01:22:57 by tischmid ### ########.fr */ +/* Updated: 2023/03/24 01:28:23 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,10 +26,11 @@ char *ft_strupcase(char *str) /* //// #include +#define STR "hello world" int main(void) { - char s1[] = "hello world"; + char s1[] = STR; printf("%s\n", s1); printf("%s\n", ft_strupcase(s1)); return (0); diff --git a/ex08/ft_strlowcase.c b/ex08/ft_strlowcase.c index 4ccc28e..f1ccb58 100644 --- a/ex08/ft_strlowcase.c +++ b/ex08/ft_strlowcase.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/19 11:18:13 by tischmid #+# #+# */ -/* Updated: 2023/03/24 01:22:44 by tischmid ### ########.fr */ +/* Updated: 2023/03/24 01:28:12 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,10 +26,11 @@ char *ft_strlowcase(char *str) /* //// #include +#define STR "hEllO worLd" int main(void) { - char s1[] = "hEllO worLd"; + char s1[] = STR; printf("%s\n", s1); printf("%s\n", ft_strlowcase(s1)); return (0); diff --git a/ex09/ft_strcapitalize.c b/ex09/ft_strcapitalize.c index 3158e15..ee7f028 100644 --- a/ex09/ft_strcapitalize.c +++ b/ex09/ft_strcapitalize.c @@ -6,48 +6,46 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/19 11:27:43 by tischmid #+# #+# */ -/* Updated: 2023/03/24 00:34:07 by tischmid ### ########.fr */ +/* Updated: 2023/03/24 01:27:57 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 +#define STR "salut, com0123456789ment tu vas ? 42mots 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); } */ //// diff --git a/ex11/ft_putstr_non_printable.c b/ex11/ft_putstr_non_printable.c index 4d9d4d8..7fb42db 100644 --- a/ex11/ft_putstr_non_printable.c +++ b/ex11/ft_putstr_non_printable.c @@ -6,48 +6,41 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#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 +#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); }