This commit is contained in:
LinlyBoi
2023-08-22 14:25:46 +03:00
parent 59e05c91fe
commit 297cf9c4a5
3 changed files with 20 additions and 6 deletions

3
main.h
View File

@@ -5,7 +5,8 @@ int _contains(const char *str, char c);
int _strlen(const char *str); int _strlen(const char *str);
char *_strcpy(char *dest, char *src); char *_strcpy(char *dest, char *src);
char *append(char *str, char c); char *append(char *str, char c);
void _puts(char *str); int _puts(char *str);
int _putchar(char c);
char* _memset(char *str, int bval); char* _memset(char *str, int bval);
#endif #endif

View File

@@ -11,7 +11,7 @@
int _printf(const char *format, ...) int _printf(const char *format, ...)
{ {
int buff_idx, fmt_idx; int buff_idx, fmt_idx;
unsigned int identifiers, BUFF_SIZE; unsigned int identifiers, BUFF_SIZE, printed;
char *buffer, *next, c; char *buffer, *next, c;
va_list args; va_list args;
@@ -26,6 +26,7 @@ int _printf(const char *format, ...)
buff_idx = 0; buff_idx = 0;
fmt_idx = 0; fmt_idx = 0;
printed = 0;
while (*(format + fmt_idx)) while (*(format + fmt_idx))
{ {
if ((*(format + fmt_idx) == '%') && (*(format + fmt_idx + 1))) if ((*(format + fmt_idx) == '%') && (*(format + fmt_idx + 1)))
@@ -68,5 +69,6 @@ int _printf(const char *format, ...)
_puts(buffer); _puts(buffer);
free(buffer); free(buffer);
} }
return (_strlen(buffer)); _putchar('\0');
return (printed);
} }

17
puts.c
View File

@@ -6,10 +6,21 @@
* *
* @str: pointers to "buffer" or string head * @str: pointers to "buffer" or string head
* *
* Return: Naught * Return: written bytes
*/ */
void _puts(char *str) int _puts(char *str)
{ {
write(1, str, _strlen(str)); return (write(1, str, _strlen(str)));
}
/**
* _putchar - writes the character c to stdout
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _putchar(char c)
{
return (write(1, &c, 1));
} }