Skip to content

Commit

Permalink
check va_list work
Browse files Browse the repository at this point in the history
  • Loading branch information
grcenneat committed Jul 15, 2020
1 parent 12841d0 commit 9ce0eaa
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
Binary file added ft_printf/Libft/libft.a
Binary file not shown.
33 changes: 29 additions & 4 deletions ft_printf/ft_printf.c
Expand Up @@ -6,15 +6,40 @@
/* By: hysimok <hysimok@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/20 01:13:55 by hysimok #+# #+# */
/* Updated: 2020/06/22 11:57:53 by hysimok ### ########.fr */
/* Updated: 2020/07/16 02:22:32 by hysimok ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdio.h>

#include "ft_printf.h"

int main(){
char word[10] = "apple";
printf("%zu\n", ft_strlen(word));
int ft_printf(const char *input, ...)
{
const char *buff;
va_list ap;
int output_len = 0;
int i, d;
char c;

i = 0;
buff = ft_strdup(input);
va_start(ap, input);
while (buff[i])
{
switch(buff[i++])
{
case 'c':
c = va_arg(ap, int);
printf("character %c\n", c);
break;
case 'd':
d = va_arg(ap, int);
printf("integer %d\n", d);
break;
}
}
va_end(ap);
free((void *)buff);
return(output_len);
}
14 changes: 14 additions & 0 deletions ft_printf/includes/ft_printf.h
@@ -1,7 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hysimok <hysimok@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 02:01:03 by hysimok #+# #+# */
/* Updated: 2020/07/16 02:01:05 by hysimok ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <unistd.h>
# include <stdarg.h>
# include "../Libft/libft.h"

int ft_printf(const char *input, ...);

#endif
10 changes: 10 additions & 0 deletions ft_printf/main.c
@@ -0,0 +1,10 @@
#include <stdio.h>

#include "ft_printf.h"

int main(){
char word[10] = "apple";
printf("%zu\n", ft_strlen(word));

ft_printf("ccdd", 'a', 'z', 9, 99);
}
2 changes: 1 addition & 1 deletion ft_printf/run.sh
@@ -1 +1 @@
gcc -Wall -Werror -Wextra ft_printf.o -I./includes -L. -lftprintf -o a.out
gcc -Wall -Werror -Wextra ft_printf.o main.c -I./includes -L. -lftprintf -o a.out

0 comments on commit 9ce0eaa

Please sign in to comment.