Untitled


SUBMITTED BY: Guest

DATE: Oct. 21, 2014, 8:28 p.m.

FORMAT: Text only

SIZE: 1.4 kB

HITS: 843

  1. #include <stdlib.h>
  2. //#include "mylist.h"
  3. typedef struct s_list
  4. {
  5. void *data;
  6. struct s_list *next;
  7. } t_list;
  8. void my_putchar(char c)
  9. {
  10. write(1, &c, 1);
  11. }
  12. int my_putstr(char *str)
  13. {
  14. int i;
  15. i = 0;
  16. while (str[i] != '\0')
  17. {
  18. my_putchar(str[i]);
  19. i++;
  20. }
  21. return (str[i]);
  22. }
  23. int my_show(t_list *dbt)
  24. {
  25. while (dbt != 0)
  26. {
  27. my_putstr(dbt->data);
  28. my_putchar('\n');
  29. dbt = dbt->next;
  30. }
  31. return (0);
  32. }
  33. int my_put_in_list(t_list **dbt, char *data)
  34. {
  35. t_list *new_elem;
  36. new_elem = malloc(sizeof(*new_elem));
  37. if (new_elem == NULL)
  38. return (0);
  39. new_elem->data = data;
  40. new_elem->next = *dbt;
  41. *dbt = new_elem;
  42. return (0);
  43. }
  44. t_list *my_params_in_list(int ac, char **av)
  45. {
  46. t_list *dbt;
  47. int i;
  48. dbt = 0;
  49. i = 0;
  50. while (i < ac)
  51. {
  52. my_put_in_list(&dbt, av[i]);
  53. i++;
  54. }
  55. return (dbt);
  56. }
  57. int main(int ac, char **av)
  58. {
  59. t_list *test;
  60. t_list **test2;
  61. test = my_params_in_list(ac, av);
  62. test2 = &test;
  63. my_show(test);
  64. return (0);

comments powered by Disqus