diff --git a/c_piscine_c_03/ex00/ft_strcmp.c b/c_piscine_c_03/ex00/ft_strcmp.c new file mode 100644 index 0000000..6a99275 --- /dev/null +++ b/c_piscine_c_03/ex00/ft_strcmp.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/02 21:32:49 by apuchill #+# #+# */ +/* Updated: 2019/12/05 00:02:15 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + int c; + + c = 0; + while ((s1[c] == s2[c]) && (s1[c] != '\0') && (s2[c] != '\0')) + c++; + return (s1[c] - s2[c]); +} diff --git a/c_piscine_c_03/ex00/t_a.out b/c_piscine_c_03/ex00/t_a.out new file mode 100755 index 0000000..cf6cf21 Binary files /dev/null and b/c_piscine_c_03/ex00/t_a.out differ diff --git a/c_piscine_c_03/ex00/t_main.c b/c_piscine_c_03/ex00/t_main.c new file mode 100644 index 0000000..ed5bc08 --- /dev/null +++ b/c_piscine_c_03/ex00/t_main.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: galves-d +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/29 00:02:08 by galves-d #+# #+# */ +/* Updated: 2019/11/29 07:05:23 by galves-d ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int ft_strcmp(char *s1, char *s2); + +int main() +{ + char s1[] = "Nada a ver"; + char s2[] = "Teste de Comparacao"; + char s3[] = "Teste"; + + printf("s12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", ft_strcmp(s1, s2), ft_strcmp(s2, s1), ft_strcmp(s1, s3), ft_strcmp(s3, s1), ft_strcmp(s2, s3), ft_strcmp(s3, s2)); + printf("\n\ns12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", strcmp(s1, s2), strcmp(s2, s1), strcmp(s1, s3), strcmp(s3, s1), strcmp(s2, s3), strcmp(s3, s2)); +} diff --git a/c_piscine_c_03/ex01/ft_strncmp.c b/c_piscine_c_03/ex01/ft_strncmp.c new file mode 100644 index 0000000..a0f5ea4 --- /dev/null +++ b/c_piscine_c_03/ex01/ft_strncmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/02 22:59:36 by apuchill #+# #+# */ +/* Updated: 2019/12/05 00:05:18 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + unsigned int c; + int diff; + + c = 0; + diff = 0; + while ((c < n) && !diff && (s1[c] != '\0') && (s2[c] != '\0')) + { + diff = (unsigned char)s1[c] - (unsigned char)s2[c]; + c++; + } + if (c < n && !diff && (s1[c] == '\0' || s2[c] == '\0')) + diff = (unsigned char)s1[c] - (unsigned char)s2[c]; + return (diff); +} diff --git a/c_piscine_c_03/ex01/t_a.out b/c_piscine_c_03/ex01/t_a.out new file mode 100755 index 0000000..67609f5 Binary files /dev/null and b/c_piscine_c_03/ex01/t_a.out differ diff --git a/c_piscine_c_03/ex01/t_main.c b/c_piscine_c_03/ex01/t_main.c new file mode 100644 index 0000000..26323e8 --- /dev/null +++ b/c_piscine_c_03/ex01/t_main.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: galves-d +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/29 00:02:08 by galves-d #+# #+# */ +/* Updated: 2019/11/29 07:06:27 by galves-d ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int ft_strncmp(char *s1, char *s2, unsigned int n); + +int main() +{ + char s1[] = "Nada a ver"; + char s2[] = "Teste de Comparacao"; + char s3[] = "Teste"; + + printf("s12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", ft_strncmp(s1, s2, 5), ft_strncmp(s2, s1, 5), ft_strncmp(s1, s3, 5), ft_strncmp(s3, s1, 5), ft_strncmp(s2, s3, 5), ft_strncmp(s3, s2, 5)); + printf("\n\ns12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", strncmp(s1, s2, 5), strncmp(s2, s1, 5), strncmp(s1, s3, 5), strncmp(s3, s1, 5), strncmp(s2, s3, 5), strncmp(s3, s2, 5)); +} diff --git a/c_piscine_c_03/ex02/ft_strcat.c b/c_piscine_c_03/ex02/ft_strcat.c new file mode 100644 index 0000000..e227dd0 --- /dev/null +++ b/c_piscine_c_03/ex02/ft_strcat.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/03 10:21:00 by apuchill #+# #+# */ +/* Updated: 2019/12/04 13:52:33 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (*str != '\0') + { + counter++; + str++; + } + return (counter); +} + +char *ft_strcat(char *dest, char *src) +{ + int c; + + c = ft_strlen(dest); + while (*src != '\0') + { + dest[c] = *src; + c++; + src++; + } + dest[c] = '\0'; + return (dest); +} diff --git a/c_piscine_c_03/ex02/t_a.out b/c_piscine_c_03/ex02/t_a.out new file mode 100755 index 0000000..e27ad2f Binary files /dev/null and b/c_piscine_c_03/ex02/t_a.out differ diff --git a/c_piscine_c_03/ex02/t_main.c b/c_piscine_c_03/ex02/t_main.c new file mode 100644 index 0000000..bd8dac7 --- /dev/null +++ b/c_piscine_c_03/ex02/t_main.c @@ -0,0 +1,15 @@ +#include + +char *ft_strcat(char *dest, char *src); + +int main(void) +{ + char dest[20] = "Hello"; + char src[] = ", world!"; + + printf("-----\ndest = %s\nsrc = %s\n", dest, src); + ft_strcat(dest, src); + printf("result = %s\n-----\n", dest); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex03/ft_strncat.c b/c_piscine_c_03/ex03/ft_strncat.c new file mode 100644 index 0000000..39371e7 --- /dev/null +++ b/c_piscine_c_03/ex03/ft_strncat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/04 14:01:10 by apuchill #+# #+# */ +/* Updated: 2019/12/05 13:11:00 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncat(char *dest, char *src, unsigned int nb) +{ + unsigned int c; + unsigned int d; + + c = 0; + d = 0; + while (dest[c] != '\0') + c++; + while (src[d] != '\0' && d < nb) + { + dest[c + d] = src[d]; + d++; + } + dest[c + d] = '\0'; + return (dest); +} diff --git a/c_piscine_c_03/ex03/t_a.out b/c_piscine_c_03/ex03/t_a.out new file mode 100755 index 0000000..dcac07a Binary files /dev/null and b/c_piscine_c_03/ex03/t_a.out differ diff --git a/c_piscine_c_03/ex03/t_main.c b/c_piscine_c_03/ex03/t_main.c new file mode 100644 index 0000000..d5cadc7 --- /dev/null +++ b/c_piscine_c_03/ex03/t_main.c @@ -0,0 +1,16 @@ +#include + +char *ft_strncat(char *dest, char *src, unsigned int nb); + +int main(void) +{ + char dest[20] = "123"; + char src[] = "4567890"; + unsigned int nb = 8; + + printf("-----\ndest = %s\nsrc = %s\nnb = %d\n", dest, src, nb); + ft_strncat(dest, src, nb); + printf("result = %s\n-----\n", dest); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex03/t_roman b/c_piscine_c_03/ex03/t_roman new file mode 100644 index 0000000..5594cc1 --- /dev/null +++ b/c_piscine_c_03/ex03/t_roman @@ -0,0 +1,17 @@ +char *ft_strncat(char *dest, char *src, unsigned int nb) +{ + unsigned int c; + unsigned int d; + + c = 0; + d = 0; + while (dest[c] != '\0') + c++; + while (src[d] != '\0' && d < nb) + { + dest[c + d] = src[d]; + d++; + } + dest[d + c] = '\0'; + return (dest); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex04/ft_strstr.c b/c_piscine_c_03/ex04/ft_strstr.c new file mode 100644 index 0000000..2783a1c --- /dev/null +++ b/c_piscine_c_03/ex04/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/04 14:36:51 by apuchill #+# #+# */ +/* Updated: 2019/12/04 21:38:22 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + int i; + int j; + + i = 0; + if (to_find[0] == '\0') + return (str); + while (str[i] != '\0') + { + j = 0; + while (str[i + j] == to_find[j] && str[i + j] != '\0') + { + if (to_find[j + 1] == '\0') + return (&str[i]); + j++; + } + i++; + } + return (0); +} diff --git a/c_piscine_c_03/ex04/t_a.out b/c_piscine_c_03/ex04/t_a.out new file mode 100755 index 0000000..a5d2aa5 Binary files /dev/null and b/c_piscine_c_03/ex04/t_a.out differ diff --git a/c_piscine_c_03/ex04/t_main.c b/c_piscine_c_03/ex04/t_main.c new file mode 100644 index 0000000..561e4a3 --- /dev/null +++ b/c_piscine_c_03/ex04/t_main.c @@ -0,0 +1,14 @@ +#include + +char *ft_strstr(char *str, char *to_find); + +int main(void) +{ + char str[] = "012340123456789"; + char to_find[] = "456"; + + printf("-----\nstr = %s\nto_find = %s\n", str, to_find); + printf("%s\n", ft_strstr(str, to_find)); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex05/ft_strlcat.c b/c_piscine_c_03/ex05/ft_strlcat.c new file mode 100644 index 0000000..7c260a5 --- /dev/null +++ b/c_piscine_c_03/ex05/ft_strlcat.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/04 21:44:39 by apuchill #+# #+# */ +/* Updated: 2019/12/05 00:03:33 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_strlen(char *str) +{ + unsigned int counter; + + counter = 0; + while (*str != '\0') + { + counter++; + str++; + } + return (counter); +} + +unsigned int ft_strlcat(char *dest, char *src, unsigned int size) +{ + unsigned int c; + unsigned int d; + + if (size <= ft_strlen(dest)) + return (size + ft_strlen(src)); + c = ft_strlen(dest); + d = 0; + while (src[d] != '\0' && c + 1 < size) + { + dest[c] = src[d]; + c++; + d++; + } + dest[c] = '\0'; + return (ft_strlen(dest) + ft_strlen(&src[d])); +} diff --git a/c_piscine_c_03/ex05/t_a.out b/c_piscine_c_03/ex05/t_a.out new file mode 100755 index 0000000..0290bb9 Binary files /dev/null and b/c_piscine_c_03/ex05/t_a.out differ diff --git a/c_piscine_c_03/ex05/t_amain.c b/c_piscine_c_03/ex05/t_amain.c new file mode 100644 index 0000000..d2eb902 --- /dev/null +++ b/c_piscine_c_03/ex05/t_amain.c @@ -0,0 +1,17 @@ +#include + +unsigned int ft_strlcat(char *dest, char *src, unsigned int size); + +int main(void) +{ + char dest[20] = "123"; + char src[] = "4567890"; + unsigned int size = 6; + unsigned int result; + + printf("-----\ndest = %s\nsrc = %s\nnb = %d\n\n", dest, src, size); + result = ft_strlcat(dest, src, size); + printf("dest (cat) = %s\nresult = %d\n-----\n", dest, result); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex05/t_main b/c_piscine_c_03/ex05/t_main new file mode 100644 index 0000000..76d1430 --- /dev/null +++ b/c_piscine_c_03/ex05/t_main @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: galves-d +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/29 05:09:22 by galves-d #+# #+# */ +/* Updated: 2019/12/03 03:45:50 by galves-d ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +unsigned int ft_strlcat(char *dest, char *src, unsigned int size); + +int main() +{ + char str0[50]; + char str1[50]; + char str2[] = "Concatenando 1"; + unsigned int tamanho1; + unsigned int tamanho2; + + str0[0] = 'O'; + str0[1] = 'l'; + str0[2] = 'a'; + str0[3] = '\0'; + + str1[0] = 'O'; + str1[1] = 'l'; + str1[2] = 'a'; + str1[3] = '\0'; + + tamanho1 = ft_strlcat(str0, str2, 0); + tamanho2 = strlcat(str1, str2, 0); + printf("String final: %s, Tamanho: %d", str0, tamanho1); + printf("\nString final: %s, Tamanho: %d", str1, tamanho2); +}