From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- rushs/tinyprintf/my_c_tail/main.c | 10 ++++++++ rushs/tinyprintf/my_c_tail/my_c_tail.c | 46 ++++++++++++++++++++++++++++++++++ rushs/tinyprintf/my_c_tail/my_c_tail.h | 6 +++++ 3 files changed, 62 insertions(+) create mode 100644 rushs/tinyprintf/my_c_tail/main.c create mode 100644 rushs/tinyprintf/my_c_tail/my_c_tail.c create mode 100644 rushs/tinyprintf/my_c_tail/my_c_tail.h (limited to 'rushs/tinyprintf/my_c_tail') diff --git a/rushs/tinyprintf/my_c_tail/main.c b/rushs/tinyprintf/my_c_tail/main.c new file mode 100644 index 0000000..ba33337 --- /dev/null +++ b/rushs/tinyprintf/my_c_tail/main.c @@ -0,0 +1,10 @@ +#include + +#include "my_c_tail.h" + +int main(int argc, char *argv[]) +{ + if (argc > 1) + stdintail(atoi(argv[1])); + return 0; +} diff --git a/rushs/tinyprintf/my_c_tail/my_c_tail.c b/rushs/tinyprintf/my_c_tail/my_c_tail.c new file mode 100644 index 0000000..790240c --- /dev/null +++ b/rushs/tinyprintf/my_c_tail/my_c_tail.c @@ -0,0 +1,46 @@ +#include "my_c_tail.h" + +#include +#include + +void stdintail(unsigned int n) +{ + char **lines = calloc(2000, sizeof(char *)); + lines[0] = malloc(350 * sizeof(char)); + size_t m = 0; + char c; + size_t i = 0; + while (read(STDIN_FILENO, &c, 1)) + { + if (c == '\n') + { + lines[m][i] = '\0'; + lines[++m] = malloc(350 * sizeof(char)); + i = 0; + } + else + { + lines[m][i++] = c; + } + } + + size_t j; + if (m > n) + { + for (size_t i = 0; i < m - n; i++) + free(lines[i]); + j = m - n; + } + else + j = 0; + + for (; j < m; j++) + { + for (size_t i = 0; lines[j][i]; i++) + write(STDOUT_FILENO, &(lines[j][i]), 1); + write(STDOUT_FILENO, "\n", 1); + free(lines[j]); + } + free(lines[m]); + free(lines); +} diff --git a/rushs/tinyprintf/my_c_tail/my_c_tail.h b/rushs/tinyprintf/my_c_tail/my_c_tail.h new file mode 100644 index 0000000..172c844 --- /dev/null +++ b/rushs/tinyprintf/my_c_tail/my_c_tail.h @@ -0,0 +1,6 @@ +#ifndef MY_C_TAIL_H +#define MY_C_TAIL_H + +void stdintail(unsigned int n); + +#endif // MY_C_TAIL_H -- cgit v1.2.3