From 5b1fface9172b819d2dc6587354c48eb1b3eb75d Mon Sep 17 00:00:00 2001 From: linlyboi Date: Tue, 19 Dec 2023 15:31:49 +0200 Subject: [PATCH] honor restored --- _printf.c | 46 ------ _putchar.c | 12 -- exclusive.c | 41 ------ proven-point/itoa.c => itoa.c | 0 main.h | 59 ++------ man_3_printf | 36 ----- proven-point/memset.c => memset.c | 0 proven-point/printf.c => printf.c | 0 proven-point/main.h | 18 --- proven-point/strings.c | 84 ----------- proven-point/tests/a | Bin 16552 -> 0 bytes proven-point/puts.c => puts.c | 0 running-out-of-names.c | 155 -------------------- special.c | 123 ---------------- proven-point/strcpy.c => strcpy.c | 0 strings.c | 159 ++++++++------------- strs2.c | 122 ---------------- {proven-point/tests => tests}/append.c | 0 {proven-point/tests => tests}/char_print.c | 0 {proven-point/tests => tests}/chonk.c | 0 {proven-point/tests => tests}/hello.c | 0 {proven-point/tests => tests}/hextest.c | 0 {proven-point/tests => tests}/itoa.c | 0 {proven-point/tests => tests}/num_test.c | 0 {proven-point/tests => tests}/puts.c | 0 {proven-point/tests => tests}/str_print.c | 0 {proven-point/tests => tests}/strcpy.c | 0 {proven-point/tests => tests}/strlen.c | 0 {proven-point/tests => tests}/test.sh | 0 29 files changed, 76 insertions(+), 779 deletions(-) delete mode 100644 _printf.c delete mode 100644 _putchar.c delete mode 100644 exclusive.c rename proven-point/itoa.c => itoa.c (100%) delete mode 100644 man_3_printf rename proven-point/memset.c => memset.c (100%) rename proven-point/printf.c => printf.c (100%) delete mode 100644 proven-point/main.h delete mode 100644 proven-point/strings.c delete mode 100755 proven-point/tests/a rename proven-point/puts.c => puts.c (100%) delete mode 100644 running-out-of-names.c delete mode 100644 special.c rename proven-point/strcpy.c => strcpy.c (100%) delete mode 100644 strs2.c rename {proven-point/tests => tests}/append.c (100%) rename {proven-point/tests => tests}/char_print.c (100%) rename {proven-point/tests => tests}/chonk.c (100%) rename {proven-point/tests => tests}/hello.c (100%) rename {proven-point/tests => tests}/hextest.c (100%) rename {proven-point/tests => tests}/itoa.c (100%) rename {proven-point/tests => tests}/num_test.c (100%) rename {proven-point/tests => tests}/puts.c (100%) rename {proven-point/tests => tests}/str_print.c (100%) rename {proven-point/tests => tests}/strcpy.c (100%) rename {proven-point/tests => tests}/strlen.c (100%) rename {proven-point/tests => tests}/test.sh (100%) diff --git a/_printf.c b/_printf.c deleted file mode 100644 index bb1f0aa..0000000 --- a/_printf.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "main.h" -/** - * _printf - printf but slow fr - * @format: identifier. - * Return: length. - */ -int _printf(const char * const format, ...) -{ - convert_match m[] = { - {"%s", printf_string}, {"%c", printf_char}, - {"%%", printf_37}, {"%i", printf_int}, - {"%d", printf_dec}, {"%r", printf_srev}, - {"%R", printf_rot13}, {"%b", printf_bin}, {"%u", printf_unsigned}, - {"%o", printf_oct}, {"%x", printf_hex}, {"%X", printf_HEX}, - {"%S", printf_exclusive_string}, {"%p", printf_pointer} - }; - - /* init list*/ - va_list args; - int i = 0, j, len = 0; - - va_start(args, format); - if (format == NULL || (format[0] == '%' && format[1] == '\0')) - return (-1); - /*jump*/ -Here: - while (format[i] != '\0') - { - j = 13; - while (j >= 0) - { - if (m[j].id[0] == format[i] && m[j].id[1] == format[i + 1]) - { - len += m[j].f(args); - i = i + 2; - goto Here; - } - j--; - } - _putchar(format[i]); - len++; - i++; - } - va_end(args); - return (len); -} diff --git a/_putchar.c b/_putchar.c deleted file mode 100644 index 313b303..0000000 --- a/_putchar.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "main.h" - -/** - * _putchar - print character - * @c: character - * - * Return: 1 - */ -int _putchar(char c) -{ - return (write(1, &c, 1)); -} diff --git a/exclusive.c b/exclusive.c deleted file mode 100644 index 96c11e1..0000000 --- a/exclusive.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "main.h" -/** - * printf_exclusive_string - print exclusuives string. - * @val: argument. - * Return: the length of the string. - */ - -int printf_exclusive_string(va_list val) -{ - char *s; - int i, len = 0; - int cast; - - s = va_arg(val, char *); - if (s == NULL) - s = "(null)"; - for (i = 0; s[i] != '\0'; i++) - { - if (s[i] < 32 || s[i] >= 127) - { - /* speical */ - _putchar('\\'); - _putchar('x'); - len = len + 2; - cast = s[i]; - if (cast < 16) - { - _putchar('0'); - len++; - } - /* epic hex */ - len = len + printf_HEX_aux(cast); - } - else - { - _putchar(s[i]); - len++; - } - } - return (len); -} diff --git a/proven-point/itoa.c b/itoa.c similarity index 100% rename from proven-point/itoa.c rename to itoa.c diff --git a/main.h b/main.h index 893129f..5f434b3 100644 --- a/main.h +++ b/main.h @@ -1,49 +1,18 @@ -#ifndef MAIN_H -#define MAIN_H - -/* important libs */ -/* they bussin frfr*/ -#include -#include +#ifndef MAIN_H_ +#define MAIN_H_ #include -#include -#include - -/** - * struct format - conversion specifiers - * @id:identifier - * @f: type pointer - */ - -typedef struct format -{ - char *id; - int (*f)(); -} convert_match; - -int printf_pointer(va_list val); -int printf_hex_aux(unsigned long int num); -int printf_HEX_aux(unsigned int num); -int printf_exclusive_string(va_list val); -int printf_HEX(va_list val); -int printf_unsigned(va_list args); -int printf_bin(va_list val); -int printf_srev(va_list args); -int printf_rot13(va_list args); -int printf_int(va_list args); -int printf_hex(va_list val); -int _strlenc(const char *s); -int rev_string(char *s); -int _strlenc(const char *s); -int printf_37(void); -int printf_char(va_list val); -int printf_string(va_list val); -int _putchar(char c); int _printf(const char *format, ...); -int printf_oct(va_list val); -int printf_dec(va_list args); -int _strlen(char *s); -int *_strcpy(char *dest, char *src); - +int _contains(const char *str, char c); +int _strlen(const char *str); +char *_strcpy(char *dest, char *src); +char *append(char *str, char c); +int _puts(char *str); +int _putchar(char c); +char *_memset(char *adr, int bval); +int fmt(char c, va_list args); +char *_str_reverse(char *str); +char *_itoa(int n, int base); +char *_uitoa(unsigned int n, int base); +char *str_up(char *s); #endif diff --git a/man_3_printf b/man_3_printf deleted file mode 100644 index 33799ed..0000000 --- a/man_3_printf +++ /dev/null @@ -1,36 +0,0 @@ -NAME - _printf -LIBRARY - nonstandard library (libmjork) -SYNOPSIS - - #include - #include - #include - #include - #include - int printf_pointer(va_list val); - int printf_hex_aux(unsigned long int num); - int printf_HEX_aux(unsigned int num); - int printf_exclusive_string(va_list val); - int printf_HEX(va_list val); - int printf_unsigned(va_list args); - int printf_bin(va_list val); - int printf_srev(va_list args); - int printf_rot13(va_list args); - int printf_int(va_list args); - int printf_hex(va_list val); - int _strlenc(const char *s); - int rev_string(char *s); - int _strlenc(const char *s); - int printf_37(void); - int printf_char(va_list val); - int printf_string(va_list val); - int _putchar(char c); - int _printf(const char *format, ...); - int printf_oct(va_list val); - int printf_dec(va_list args); - int _strlen(char *s); - int *_strcpy(char *dest, char *src); -DESCRIPTION - I PROVED A POINT AND THATS WHAT MATTERS diff --git a/proven-point/memset.c b/memset.c similarity index 100% rename from proven-point/memset.c rename to memset.c diff --git a/proven-point/printf.c b/printf.c similarity index 100% rename from proven-point/printf.c rename to printf.c diff --git a/proven-point/main.h b/proven-point/main.h deleted file mode 100644 index 5f434b3..0000000 --- a/proven-point/main.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MAIN_H_ -#define MAIN_H_ -#include -int _printf(const char *format, ...); -int _contains(const char *str, char c); -int _strlen(const char *str); -char *_strcpy(char *dest, char *src); -char *append(char *str, char c); -int _puts(char *str); -int _putchar(char c); -char *_memset(char *adr, int bval); -int fmt(char c, va_list args); -char *_str_reverse(char *str); -char *_itoa(int n, int base); -char *_uitoa(unsigned int n, int base); -char *str_up(char *s); - -#endif diff --git a/proven-point/strings.c b/proven-point/strings.c deleted file mode 100644 index 7480802..0000000 --- a/proven-point/strings.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "main.h" -#include - -/** - * _strlen - Takes string and return its length - * - * @str: Address to the head of the string (Array of Characters) (Lost btw) - * - * Return: Length of String - */ -int _strlen(const char *str) -{ - if (*str) - return (1 + _strlen(++str)); - else - return (0); -} - -/** - * _contains - gets number of unique identifiers - * - * @str: da string - * @c: basically almost always '%' - * - * Return: number of unique cases of "%*" that aren't "%%" - */ -int _contains(const char *str, char c) -{ - if (*str) - { - if (*str == c && *(str + 1) != c && *(str - 1) != c) - return (1 + _contains(str + 1, c)); - else - return (_contains(str + 1, c)); - } - else - return (0); -} - -/** - * append - shoved character at the end - * - * @str: main string - * @c: character getting shoved - * - * Return: da string but appended - */ - -char *append(char *str, char c) -{ - int len, i; - char *new_me; - - len = _strlen(str); - - new_me = malloc(len + 1); - i = -1; - while (*(str + ++i)) - *(new_me + i) = *(str + i); - - *(new_me + i++) = c; - *(new_me + len + 1) = '\0'; - return (new_me); -} - -/** - * str_up - changes all lowercase letters of a string - * to uppercase - * @s: string to modify - * - * Return: the resulting string - */ -char *str_up(char *s) -{ - int i; - - for (i = 0; s[i] != '\0'; i++) - { - if (s[i] >= 'a' && s[i] <= 'z') - s[i] = s[i] - 32; - } - - return (s); -} diff --git a/proven-point/tests/a b/proven-point/tests/a deleted file mode 100755 index 11aa41de55a9f7cd35eb15936de2c296f4ec5baf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16552 zcmeHOdyrGr89xai3!+(YQGAjL+p;2og@tZaG(0X`91tq(v`%a9W|J(Nc9X2hO#ug# z8rC5VJGE17nQ6ztKRRk{9h_>X4&+W$gHGZE@aG4;k6~vY56%y8ha;vU@ghi`32j8>B zW#TOG6D6kPVMQQS<+y(|t<(4fP_mmvl`-fg3KmQ`LZW0hUa3$(C`^U!2iZ*`f#$um zPY1@7<<<6rWQ-D&-&MLt_m8RDjzT%GKT6I3XbP*Y$F!kDXX*(}nt;_^dYJXIZyD})<2ru2KV8N8z`y%Z0 z&}xm3Cp^qI>h{JPhjyKRraHZ1VRxcqSCj@?FvS(b zhvwAU8`=cilnB#l6#m_cXMZGX&~nn>yCihWoWCwT_Ug)g9ltqp?d{*3^78GZLvfQ0 z=};kmJVl77`V@RfN9E&Ns40x-vG|KgqT`i?5X=}uc zgbcWFp7Vs4UAUT`gyMST!nqB?D=wVoH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ZYw&(o<(;?+n#z=YQ{_}l% z0vO#gvOVuVm_DZMnUD{6xdjZ}%doL6z_Ov%(p7#e#!@4obu{(YZ zi#}8+r)+;*?;n_!w4yhE-2WeF`;}Uc_diVAUG`+-&EI{%C@%J2{XNsaYrHSiZe*-n zC;B6N-1b3j$8?ih8FekL()&I3Jz9Y&>$4l?nI81m@74mQVK&s1?U??`V_(t&rccqp zxeD7c^b{)Y{`37FQ{H#8zIXjRukCsKMNn&MdWB}0@c1!L_y5#B+g}+}5~e#9TmAO7 z|0hV?_74P=D$^4rbQN#=Z$d`@`|>`QpC|CSTCYCyOy7lVz-7?RkH4U?D)1cKJQ>#r90kg0b6PgthJ>MY$dJ zz;?_}gE3*;KHrztYkRLgwdF3;b^BVqDq{QjRYX 0) - { - while (num / 10 != 0) - { - exp = exp * 10; - num = num / 10; - } - num = n; - while (exp > 0) - { - digit = num / exp; - _putchar(digit + '0'); - num = num - (digit * exp); - exp = exp / 10; - i++; - } - } - _putchar(last + '0'); - - return (i); -} - -#include "main.h" - -/** - * printf_oct - prints an octal number. - * @val: arguments. - * Return: counter. - */ -int printf_oct(va_list val) -{ - int i; - int *array; - int counter = 0; - unsigned int num = va_arg(val, unsigned int); - unsigned int temp = num; - - while (num / 8 != 0) - { - num /= 8; - counter++; - } - counter++; - array = malloc(counter * sizeof(int)); - - for (i = 0; i < counter; i++) - { - array[i] = temp % 8; - temp /= 8; - } - for (i = counter - 1; i >= 0; i--) - { - _putchar(array[i] + '0'); - } - free(array); - return (counter); -} - -/** - * printf_hex_aux - prints an hexgecimal number. - * @num: arguments. - * Return: counter. - */ -int printf_hex_aux(unsigned long int num) -{ - long int i; - long int *array; - long int counter = 0; - unsigned long int temp = num; - - while (num / 16 != 0) - { - num /= 16; - counter++; - } - counter++; - array = malloc(counter * sizeof(long int)); - - for (i = 0; i < counter; i++) - { - array[i] = temp % 16; - temp /= 16; - } - for (i = counter - 1; i >= 0; i--) - { - if (array[i] > 9) - array[i] = array[i] + 39; - _putchar(array[i] + '0'); - } - free(array); - return (counter); -} - -/** - * printf_hex - prints an hexgecimal number. - * @val: arguments. - * Return: counter. - */ -int printf_hex(va_list val) -{ - int i; - int *array; - int counter = 0; - unsigned int num = va_arg(val, unsigned int); - unsigned int temp = num; - - while (num / 16 != 0) - { - num /= 16; - counter++; - } - counter++; - array = malloc(counter * sizeof(int)); - - for (i = 0; i < counter; i++) - { - array[i] = temp % 16; - temp /= 16; - } - for (i = counter - 1; i >= 0; i--) - { - if (array[i] > 9) - array[i] = array[i] + 39; - _putchar(array[i] + '0'); - } - free(array); - return (counter); -} diff --git a/special.c b/special.c deleted file mode 100644 index 3ea4e69..0000000 --- a/special.c +++ /dev/null @@ -1,123 +0,0 @@ -#include "main.h" -/** - * printf_37 - prints % - * Return: 1. - */ -int printf_37(void) -{ - _putchar(37); - return (1); -} - -/** - * printf_rot13 - ROT13 CAESAR's AMAZING CIPHEER - * @args: STRING - * Return:coun - */ -int printf_rot13(va_list args) -{ - int i, j, counter = 0; - int k = 0; - char *s = va_arg(args, char*); - /* basic alphabet */ - char alpha[] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; - /* shifted by 13 */ - char beta[] = {"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"}; - - if (s == NULL) - s = "(null)"; - for (i = 0; s[i]; i++) - { - k = 0; - for (j = 0; alpha[j] && !k; j++) - { - if (s[i] == alpha[j]) - { - _putchar(beta[j]); - counter++; - k = 1; - } - } - if (!k) - { - _putchar(s[i]); - counter++; - } - } - return (counter); -} - -/** - * printf_pointer - prints an hexdecimal number. - * @val: arguments. - * Return: counter. - */ -int printf_pointer(va_list val) -{ - void *p; - char *s = "(nil)"; - long int a; - int b; - int i; - - p = va_arg(val, void*); - if (p == NULL) - { - for (i = 0; s[i] != '\0'; i++) - { - _putchar(s[i]); - } - return (i); - } - - a = (unsigned long int)p; - _putchar('0'); - _putchar('x'); - b = printf_hex_aux(a); - return (b + 2); -} - -/** - * printf_int - prints integer - * @args: argument to print - * Return: number of characters printed - */ - -int printf_int(va_list args) -{ - int n = va_arg(args, int); - int num, last = n % 10, digit, exp = 1; - int i = 1; - - n = n / 10; - num = n; - - if (last < 0) - { - _putchar('-'); - num = -num; - n = -n; - last = -last; - i++; - } - if (num > 0) - { - while (num / 10 != 0) - { - exp = exp * 10; - num = num / 10; - } - num = n; - while (exp > 0) - { - digit = num / exp; - _putchar(digit + '0'); - num = num - (digit * exp); - exp = exp / 10; - i++; - } - } - _putchar(last + '0'); - - return (i); -} diff --git a/proven-point/strcpy.c b/strcpy.c similarity index 100% rename from proven-point/strcpy.c rename to strcpy.c diff --git a/strings.c b/strings.c index f871c01..7480802 100644 --- a/strings.c +++ b/strings.c @@ -1,119 +1,84 @@ #include "main.h" +#include /** - * printf_char - char. - * @val: args - * Return: 1 + * _strlen - Takes string and return its length + * + * @str: Address to the head of the string (Array of Characters) (Lost btw) + * + * Return: Length of String */ -int printf_char(va_list val) +int _strlen(const char *str) { - char s; - - s = va_arg(val, int); - _putchar(s); - return (1); + if (*str) + return (1 + _strlen(++str)); + else + return (0); } /** - * printf_bin - binary number. - * @val: arguments. - * Return: 1 + * _contains - gets number of unique identifiers + * + * @str: da string + * @c: basically almost always '%' + * + * Return: number of unique cases of "%*" that aren't "%%" */ -int printf_bin(va_list val) +int _contains(const char *str, char c) { - /* inits */ - int flag = 0; - int cont = 0; - int i, a = 1, b; - unsigned int num = va_arg(val, unsigned int); - unsigned int p; - - for (i = 0; i < 32; i++) + if (*str) { - p = ((a << (31 - i)) & num); - if (p >> (31 - i)) - flag = 1; - if (flag) - { - b = p >> (31 - i); - _putchar(b + 48); - cont++; - } + if (*str == c && *(str + 1) != c && *(str - 1) != c) + return (1 + _contains(str + 1, c)); + else + return (_contains(str + 1, c)); } - if (cont == 0) - { - cont++; - _putchar('0'); - } - return (cont); + else + return (0); } + /** - * printf_HEX - prints an hexdecimal number. - * @val: arguments. - * Return: counter. + * append - shoved character at the end + * + * @str: main string + * @c: character getting shoved + * + * Return: da string but appended */ -int printf_HEX(va_list val) + +char *append(char *str, char c) +{ + int len, i; + char *new_me; + + len = _strlen(str); + + new_me = malloc(len + 1); + i = -1; + while (*(str + ++i)) + *(new_me + i) = *(str + i); + + *(new_me + i++) = c; + *(new_me + len + 1) = '\0'; + return (new_me); +} + +/** + * str_up - changes all lowercase letters of a string + * to uppercase + * @s: string to modify + * + * Return: the resulting string + */ +char *str_up(char *s) { int i; - int *arr; - int counter = 0; - unsigned int num = va_arg(val, unsigned int); - unsigned int temp = num; - while (num / 16 != 0) + for (i = 0; s[i] != '\0'; i++) { - num /= 16; - counter++; + if (s[i] >= 'a' && s[i] <= 'z') + s[i] = s[i] - 32; } - counter++; - arr = malloc(counter * sizeof(int)); - for (i = 0; i < counter; i++) - { - arr[i] = temp % 16; - temp /= 16; - } - for (i = counter - 1; i >= 0; i--) - { - if (arr[i] > 9) - arr[i] = arr[i] + 7; - _putchar(arr[i] + '0'); - } - free(arr); - return (counter); -} - -/** - * printf_HEX_aux - prints an hexdecimal number. - * @num: number to print. - * Return: counter. - */ -int printf_HEX_aux(unsigned int num) -{ - int i; - int *arr; - int counter = 0; - unsigned int temp = num; - - while (num / 16 != 0) - { - num /= 16; - counter++; - } - counter++; - arr = malloc(counter * sizeof(int)); - - for (i = 0; i < counter; i++) - { - arr[i] = temp % 16; - temp /= 16; - } - for (i = counter - 1; i >= 0; i--) - { - if (arr[i] > 9) - arr[i] = arr[i] + 7; - _putchar(arr[i] + '0'); - } - free(arr); - return (counter); + return (s); } diff --git a/strs2.c b/strs2.c deleted file mode 100644 index 208b1be..0000000 --- a/strs2.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "main.h" -/** - * _strlen - Returns the length. - * @s: char pointer - * Return: c. - */ -int _strlen(char *s) -{ - int c; - - for (c = 0; s[c] != 0; c++) - ; - return (c); - -} -/** - * _strlenc - char pointer - * @s: char pointer - * Return: c - */ -int _strlenc(const char *s) -{ - int c; - - for (c = 0; s[c] != 0; c++) - ; - return (c); -} - -/** - * printf_string - print a string. - * @val: argument. - * Return: the length of the string. - */ - -int printf_string(va_list val) -{ - char *s; - int i, len; - - s = va_arg(val, char *); - if (s == NULL) - { - s = "(null)"; - len = _strlen(s); - for (i = 0; i < len; i++) - _putchar(s[i]); - return (len); - } - else - { - len = _strlen(s); - for (i = 0; i < len; i++) - _putchar(s[i]); - return (len); - } -} - -/** - * printf_unsigned - integer - * @args: argument - * Return: number of chars printed - */ -int printf_unsigned(va_list args) -{ - unsigned int n = va_arg(args, unsigned int); - int num, last = n % 10, digit, exp = 1; - int i = 1; - - n = n / 10; - num = n; - - if (last < 0) - { - _putchar('-'); - num = -num; - n = -n; - last = -last; - i++; - } - if (num > 0) - { - while (num / 10 != 0) - { - exp = exp * 10; - num = num / 10; - } - num = n; - while (exp > 0) - { - digit = num / exp; - _putchar(digit + '0'); - num = num - (digit * exp); - exp = exp / 10; - i++; - } - } - _putchar(last + '0'); - - return (i); -} - -/** - * printf_srev - function that prints a str in reverse - * @args: va_arg arguments - * Return: the string - */ -int printf_srev(va_list args) -{ - - char *s = va_arg(args, char*); - int i; - int j = 0; - - if (s == NULL) - s = "(null)"; - while (s[j] != '\0') - j++; - for (i = j - 1; i >= 0; i--) - _putchar(s[i]); - return (j); -} diff --git a/proven-point/tests/append.c b/tests/append.c similarity index 100% rename from proven-point/tests/append.c rename to tests/append.c diff --git a/proven-point/tests/char_print.c b/tests/char_print.c similarity index 100% rename from proven-point/tests/char_print.c rename to tests/char_print.c diff --git a/proven-point/tests/chonk.c b/tests/chonk.c similarity index 100% rename from proven-point/tests/chonk.c rename to tests/chonk.c diff --git a/proven-point/tests/hello.c b/tests/hello.c similarity index 100% rename from proven-point/tests/hello.c rename to tests/hello.c diff --git a/proven-point/tests/hextest.c b/tests/hextest.c similarity index 100% rename from proven-point/tests/hextest.c rename to tests/hextest.c diff --git a/proven-point/tests/itoa.c b/tests/itoa.c similarity index 100% rename from proven-point/tests/itoa.c rename to tests/itoa.c diff --git a/proven-point/tests/num_test.c b/tests/num_test.c similarity index 100% rename from proven-point/tests/num_test.c rename to tests/num_test.c diff --git a/proven-point/tests/puts.c b/tests/puts.c similarity index 100% rename from proven-point/tests/puts.c rename to tests/puts.c diff --git a/proven-point/tests/str_print.c b/tests/str_print.c similarity index 100% rename from proven-point/tests/str_print.c rename to tests/str_print.c diff --git a/proven-point/tests/strcpy.c b/tests/strcpy.c similarity index 100% rename from proven-point/tests/strcpy.c rename to tests/strcpy.c diff --git a/proven-point/tests/strlen.c b/tests/strlen.c similarity index 100% rename from proven-point/tests/strlen.c rename to tests/strlen.c diff --git a/proven-point/tests/test.sh b/tests/test.sh similarity index 100% rename from proven-point/tests/test.sh rename to tests/test.sh