Guest User

Untitled

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