Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdarg.h>
- 12 int function(char *str, int i, va_list args)
- 13 {
- 14 if (str[i + 1] == 'd')
- 15 {
- 16 my_put_nbr(va_arg(args, int));
- 17 }
- 18 if ((str[i + 1]) == 'c')
- 19 my_putchar((char)va_arg(args, int));
- 20 if (str[i + 1] == 's')
- 21 my_putstr(va_arg(args, char*));
- 22 // if (str[i + 1] == 'p')
- 23 //addresse pointeur
- 24 //if (str[i + 1] == 'x')
- 25 //put hexadecimal
- 26 return (0);
- 27 }
- 28
- 29 void my_printf(char *str, ...)
- 30 {
- 31 int i;
- 32 va_list args;
- 33
- 34 va_start(args, str);
- 35 i = 0;
- 36 while (str[i] != '\0')
- 37 {
- 38 if (str[i] == '%')
- 39 {
- 40 function(str, i, args);
- 41 i = i + 2;
- 42 }
- 43 if (str[i] == '\n')
- 44 my_putstr("\n");
- 45 else
- 46 my_putchar(str[i]);
- 47 i = i + 1;
- 48 }
- 49 va_end(args);
- 50 }
- 51
- 52
- 53 int main(int argc, char **argv)
- 54 {
- 55 my_printf("ceci est un\n %d test??? %d \n", 150, 300);
- 56 return (0);
- 57 }
- ~/Documents/local/printf/my_printf.c Line:56/57,12 98%
- "my_printf.c" 57L, 1122C écrit(s)
Add Comment
Please, Sign In to add comment