-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
24 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,24 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/28 15:56:14 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/04 15:44:30 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/04 15:55:04 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_printf.h" | ||
#include <stdarg.h> | ||
#include <stddef.h> | ||
|
||
size_t ft_putchar(char c); | ||
size_t ft_putstr(char *s); | ||
size_t num_len(int n); | ||
size_t ft_putnbr(int n); | ||
size_t ft_putchar(char c); | ||
size_t ft_putstr(char *s); | ||
size_t num_len(int n); | ||
size_t ft_putnbr(int n); | ||
size_t ft_puthex(unsigned int nbr, char *base); | ||
|
||
int ft_parse(va_list ap, const char c) | ||
{ | ||
size_t len; | ||
void *ptr; | ||
|
||
len = 0; | ||
if (c == 'c' || c == '%') | ||
|
@@ -34,13 +35,11 @@ int ft_parse(va_list ap, const char c) | |
else if (c == 'u') | ||
len += ft_unsigned_putnbr(va_arg(ap, unsigned int)); | ||
else if (c == 'x') | ||
len += ft_puthex(va_arg(ap, int), "0123456789abcdef"); | ||
len += ft_puthex(va_arg(ap, int), "0123456789abcdef"); | ||
else if (c == 'X') | ||
len += ft_puthex(va_arg(ap, int), "0123456789ABCDEF"); | ||
len += ft_puthex(va_arg(ap, int), "0123456789ABCDEF"); | ||
else if (c == 'p') | ||
{ | ||
void *ptr; | ||
|
||
ptr = va_arg(ap, void *); | ||
if (!ptr) | ||
len += write(1, "(nil)", 5); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,16 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/25 17:49:25 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/04 15:39:09 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/04 15:48:50 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_printf.h" | ||
#include <stdarg.h> | ||
#include <stdlib.h> | ||
|
||
int ft_parse(va_list ap, const char c); | ||
size_t ft_putchar(char c); | ||
int ft_parse(va_list ap, const char c); | ||
size_t ft_putchar(char c); | ||
|
||
int ft_printf(const char *format, ...) | ||
{ | ||
|
@@ -43,14 +43,3 @@ int ft_printf(const char *format, ...) | |
va_end(ap); | ||
return (len); | ||
} | ||
|
||
/* | ||
#include <limits.h> | ||
int main(void) | ||
{ | ||
__builtin_printf("%d\n", ft_printf("%p", LONG_MIN)); | ||
__builtin_printf("%d\n", __builtin_printf("%p", LONG_MIN)); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,23 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/29 14:24:31 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/04 15:44:08 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/04 15:56:15 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef FT_PRINTF_H | ||
# define FT_PRINTF_H | ||
|
||
#include <stdarg.h> | ||
#include <unistd.h> | ||
# include <stdarg.h> | ||
# include <unistd.h> | ||
|
||
int ft_printf(const char *format, ...); | ||
size_t ft_putchar(char c); | ||
size_t ft_putstr(char *s); | ||
size_t num_len(int n); | ||
size_t ft_putnbr(int n); | ||
size_t ft_unsigned_putnbr(unsigned int n); | ||
int ft_parse(va_list ap, const char c); | ||
int ft_printf(const char *format, ...); | ||
size_t ft_putchar(char c); | ||
size_t ft_putstr(char *s); | ||
size_t num_len(int n); | ||
size_t ft_putnbr(int n); | ||
size_t ft_unsigned_putnbr(unsigned int n); | ||
int ft_parse(va_list ap, const char c); | ||
size_t ft_puthex(unsigned int nbr, char *base); | ||
size_t ft_putptr(unsigned long nbr, char *base); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,20 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/28 16:49:00 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/04 15:42:36 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/04 15:47:53 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_printf.h" | ||
#include <unistd.h> | ||
#include <stddef.h> | ||
|
||
size_t ft_putchar(char c) | ||
{ | ||
return (write(1, &c, 1)); | ||
} | ||
|
||
size_t ft_putstr(char *s) | ||
size_t ft_putstr(char *s) | ||
{ | ||
size_t i; | ||
|
||
|