-
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.
fix errors. Printf works for char, string and int
- Loading branch information
Showing
3 changed files
with
24 additions
and
17 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 |
---|---|---|
@@ -1,27 +1,33 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_parser.c :+: :+: :+: */ | ||
/* ft_parse.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/28 15:56:14 by dsemenov #+# #+# */ | ||
/* Updated: 2024/11/28 18:02:35 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/11/28 20:04:18 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#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); | ||
|
||
int ft_parse(va_list ap, const char c) | ||
{ | ||
size_t len; | ||
|
||
len = 0; | ||
if (c == 'c' || c == '%') | ||
len += ft_putchar(va_arg(ap, char)); | ||
len += ft_putchar(va_arg(ap, int)); | ||
else if (c == 's') | ||
len += ft_putstr(va_arg(ap, char *)); | ||
else if (c == 'd' || 'i') | ||
else if (c == 'd' || c == 'i') | ||
len += ft_putnbr(va_arg(ap, int)); | ||
return (len); | ||
} |
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,15 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/25 17:49:25 by dsemenov #+# #+# */ | ||
/* Updated: 2024/11/28 16:44:03 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/11/28 20:10:05 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdarg.h> | ||
#include <stdlib.h> | ||
|
||
int ft_putchar(char c); | ||
|
||
int ft_putstr(char *s); | ||
int ft_parse(va_list ap, const char c); | ||
size_t ft_putchar(char c); | ||
|
||
int ft_printf(const char *format, ...) | ||
{ | ||
|
@@ -37,7 +36,7 @@ int ft_printf(const char *format, ...) | |
format++; | ||
} | ||
else | ||
ft_parse(va_arg(ap, c)); | ||
ft_parse(ap, *format); | ||
} | ||
format++; | ||
} | ||
|
@@ -47,6 +46,9 @@ int ft_printf(const char *format, ...) | |
|
||
int main(void) | ||
{ | ||
__builtin_printf("%d", ft_printf("Hello")); | ||
int i = 55; | ||
char str[] = "NATHAN LE BG"; | ||
char c = 'X'; | ||
ft_printf("Hello, number is %d\n%s\n%c", i, str, c); | ||
|
||
} |
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,7 +6,7 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/28 16:49:00 by dsemenov #+# #+# */ | ||
/* Updated: 2024/11/28 17:55:49 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/11/28 20:03:43 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -59,15 +59,14 @@ size_t ft_putnbr(int n) | |
|
||
if (n == -2147483648) | ||
return (ft_putstr("-2147483648")); | ||
nbr = n; | ||
if (n < 0) | ||
{ | ||
nbr = -nbr; | ||
ft_putchar('-'); | ||
|
||
} | ||
if (nbr >= 10) | ||
ft_putnbr(nbr / 10); | ||
ft_putchar(nbr % 10 + '0'); | ||
return (num_len(n)); | ||
} | ||
|
||
int main(void) | ||
{ | ||
__builtin_printf("%zu\n", ft_putnbr(-2147483648)); | ||
} |