aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-08-06 18:19:11 +0200
committerCharles <sircharlesaze@gmail.com>2019-08-06 18:19:11 +0200
commitc6d343fccb84e9fc89dfc75b3f35a352e97b14a4 (patch)
tree5cde66a3b489c7882b6d7ba062df5a70dbaf0666
parent056a88ee9c2c9e26f9712d14c645e367d851f394 (diff)
downloadpiscine-c6d343fccb84e9fc89dfc75b3f35a352e97b14a4.tar.gz
piscine-c6d343fccb84e9fc89dfc75b3f35a352e97b14a4.tar.bz2
piscine-c6d343fccb84e9fc89dfc75b3f35a352e97b14a4.zip
details, print_memory start
- copied c09 correct ft_split to c07 - strdup parenthesis in malloc - strlcat copied from tested libft
-rw-r--r--c02/ex12/ft_print_memory.c44
-rw-r--r--c02/main.c14
-rw-r--r--c03/ex05/ft_strlcat.c2
-rw-r--r--c07/ex00/ft_strdup.c2
-rw-r--r--c07/ex05/ft_split.c5
5 files changed, 60 insertions, 7 deletions
diff --git a/c02/ex12/ft_print_memory.c b/c02/ex12/ft_print_memory.c
new file mode 100644
index 0000000..442d6e4
--- /dev/null
+++ b/c02/ex12/ft_print_memory.c
@@ -0,0 +1,44 @@
+#include <unistd.h>
+
+void xy_putchar(char c)
+{
+ write(1, &c, 1);
+}
+
+void *ft_print_memory(void *addr, unsigned int size)
+{
+ int i;
+ unsigned char *cursor;
+ char *hex_symbols;
+
+ cursor = (unsigned char*)addr;
+ hex_symbols = "0123456789abcdef";
+ i = 0;
+ /* while (i < size) */
+ /* { */
+ /* i = 0; */
+ while (i < size)
+ {
+ xy_putchar(hex_symbols[cursor[i] / 16]);
+ xy_putchar(hex_symbols[cursor[i] % 16]);
+ if ((i + 1) % 2 == 0)
+ xy_putchar(' ');
+ i++;
+ /* } */
+ /* i = 0; */
+ /* while(i % 16 != 0 && i < size) */
+ /* { */
+ /* i++; */
+ /* } */
+ /* i = 0; */
+ /* while(i % 16 != 0 && i < size) */
+ /* { */
+ /* cursor++; */
+ /* i++; */
+ /* } */
+ /* i++; */
+ }
+ return (addr);
+}
+
+//if (cursor[i] >= ' ' && cursor[i] <= '~')
diff --git a/c02/main.c b/c02/main.c
index 1e41286..e9f0a47 100644
--- a/c02/main.c
+++ b/c02/main.c
@@ -1,5 +1,8 @@
-#include <stdio.h>
+#ifdef linux
+# include <bsd/string.h> // with -lbsd
+#endif
#include <string.h>
+#include <stdio.h>
#include <limits.h>
#include "ex00/ft_strcpy.c"
#include "ex01/ft_strncpy.c"
@@ -13,6 +16,7 @@
#include "ex09/ft_strcapitalize.c"
#include "ex10/ft_strlcpy.c"
#include "ex11/ft_putstr_non_printable.c"
+#include "ex12/ft_print_memory.c"
int main()
{
@@ -77,9 +81,9 @@ int main()
ft_strcapitalize(tocap);
printf("%s\n", tocap);
- char a[] = "qweihroqwier";
+ /* char a[] = "qweihroqwier"; */
char ldest[6];
- char b[] = "qweqweeqwrqwer";
+ /* char b[] = "qweqweeqwrqwer"; */
char lsrc[] = "qwroiqwer";
printf("len %u : ", ft_strlcpy(ldest, lsrc, sizeof ldest ));
for (int i = 0; i < 33; i++)
@@ -101,5 +105,9 @@ int main()
}
ft_putstr_non_printable("Coucou\ntu vas bien ?");
+ printf("\n---------------------\n");
+ char *addr = "bonjour je suis charles et je le suis bien";
+ ft_print_memory(addr, sizeof addr);
+
return 0;
}
diff --git a/c03/ex05/ft_strlcat.c b/c03/ex05/ft_strlcat.c
index 1e7f9dc..ae84e43 100644
--- a/c03/ex05/ft_strlcat.c
+++ b/c03/ex05/ft_strlcat.c
@@ -31,7 +31,7 @@ unsigned int ft_strlcat(char *dest, char *src, unsigned int size)
if (size == 0)
return (src_len);
i = dest_len;
- while (i < size - 1 && src[i - dest_len])
+ while (i < size - 1)
{
dest[i] = src[i - dest_len];
i++;
diff --git a/c07/ex00/ft_strdup.c b/c07/ex00/ft_strdup.c
index 754f317..4cf3b3a 100644
--- a/c07/ex00/ft_strdup.c
+++ b/c07/ex00/ft_strdup.c
@@ -28,7 +28,7 @@ char *ft_strdup(char *src)
int i;
char *dup_ptr;
- dup_ptr = (char*)malloc(sizeof(char) * ft_strlen(src) + 1);
+ dup_ptr = (char*)malloc(sizeof(char) * (ft_strlen(src) + 1));
if (dup_ptr == NULL)
{
errno = ENOMEM;
diff --git a/c07/ex05/ft_split.c b/c07/ex05/ft_split.c
index 3ff2e43..a11477f 100644
--- a/c07/ex05/ft_split.c
+++ b/c07/ex05/ft_split.c
@@ -6,7 +6,7 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/08 15:58:03 by cacharle #+# #+# */
-/* Updated: 2019/07/13 08:15:31 by cacharle ### ########.fr */
+/* Updated: 2019/07/16 09:18:23 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -62,7 +62,8 @@ char **heck(char *str, char *charset, char *tmp, int i)
while (!in_charset(*str, charset) && *str)
tmp[i++] = *str++;
tmp[i] = '\0';
- strs[j++] = tmp;
+ if (i != 0)
+ strs[j++] = tmp;
}
strs[j] = 0;
return (strs);