Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. gcc -c -Wall -Wextra -Werror ft_putchar.c ft_swap.c ft_putstr.c ft_strlen.c ft_strcmp.c &&
  4. ar r libft.a ft_putchar.o ft_swap.o ft_putstr.o ft_strlen.o ft_strcmp.o && rm *.o
  5. /* ************************************************************************** */
  6. /* */
  7. /* ::: :::::::: */
  8. /* ft_print_program_name.c :+: :+: :+: */
  9. /* +:+ +:+ +:+ */
  10. /* By: dcaudoux <[email protected]> +#+ +:+ +#+ */
  11. /* +#+#+#+#+#+ +#+ */
  12. /* Created: 2017/08/14 06:40:03 by dcaudoux #+# #+# */
  13. /* Updated: 2017/08/17 23:06:18 by dcaudoux ### ########.fr */
  14. /* */
  15. /* ************************************************************************** */
  16.  
  17. #include <unistd.h>
  18. #include <stdio.h>
  19.  
  20. void ft_putchar(char c);
  21.  
  22. void ft_putstr(char *str)
  23. {
  24. int i;
  25.  
  26. i = 0;
  27. while (str[i] != '\0')
  28. {
  29. ft_putchar(str[i]);
  30. i++;
  31. }
  32. }
  33.  
  34. int main(int argc, char **argv)
  35. {
  36. argc = 0;
  37. ft_putstr(argv[0]);
  38. ft_putchar('\n');
  39. return (0);
  40. }
  41. /* ************************************************************************** */
  42. /* */
  43. /* ::: :::::::: */
  44. /* ft_putchar.c :+: :+: :+: */
  45. /* +:+ +:+ +:+ */
  46. /* By: dcaudoux <[email protected]> +#+ +:+ +#+ */
  47. /* +#+#+#+#+#+ +#+ */
  48. /* Created: 2017/08/14 05:39:05 by dcaudoux #+# #+# */
  49. /* Updated: 2017/08/17 02:19:55 by dcaudoux ### ########.fr */
  50. /* */
  51. /* ************************************************************************** */
  52.  
  53. #include <unistd.h>
  54.  
  55. void ft_putchar(char c);
  56.  
  57. void ft_putstr(char *str)
  58. {
  59. int i;
  60.  
  61. i = 0;
  62. while (str[i])
  63. {
  64. ft_putchar(str[i]);
  65. i++;
  66. }
  67. }
  68.  
  69. int main(int argc, char **argv)
  70. {
  71. int i;
  72.  
  73. i = 1;
  74. if (argc == 1)
  75. {
  76. return (0);
  77. }
  78. while (argv[i] != '\0')
  79. {
  80. ft_putstr(argv[i]);
  81. i++;
  82. ft_putchar('\n');
  83. }
  84. return (0);
  85. }
  86. /* ************************************************************************** */
  87. /* */
  88. /* ::: :::::::: */
  89. /* ft_print_program_name.c :+: :+: :+: */
  90. /* +:+ +:+ +:+ */
  91. /* By: dcaudoux <[email protected]> +#+ +:+ +#+ */
  92. /* +#+#+#+#+#+ +#+ */
  93. /* Created: 2017/08/14 06:40:03 by dcaudoux #+# #+# */
  94. /* Updated: 2017/08/17 01:16:29 by dcaudoux ### ########.fr */
  95. /* */
  96. /* ************************************************************************** */
  97.  
  98. #include <unistd.h>
  99. #include <stdio.h>
  100.  
  101. void ft_putchar(char c);
  102.  
  103. void ft_putstr(char *str)
  104. {
  105. int i;
  106.  
  107. i = 0;
  108. while (str[i] != '\0')
  109. {
  110. ft_putchar(str[i]);
  111. i++;
  112. }
  113. }
  114.  
  115. int main(int argc, char **argv)
  116. {
  117. int i;
  118. int j;
  119.  
  120. i = argc - 1;
  121. while (i > 0)
  122. {
  123. j = 0;
  124. while (argv[i][j])
  125. {
  126. ft_putchar(argv[i][j]);
  127. j++;
  128. }
  129. ft_putchar('\n');
  130. i--;
  131. }
  132. return (0);
  133. }
  134. /* ************************************************************************** */
  135. /* */
  136. /* ::: :::::::: */
  137. /* ft_sort_params.c :+: :+: :+: */
  138. /* +:+ +:+ +:+ */
  139. /* By: dcaudoux <[email protected]> +#+ +:+ +#+ */
  140. /* +#+#+#+#+#+ +#+ */
  141. /* Created: 2017/08/17 01:19:58 by dcaudoux #+# #+# */
  142. /* Updated: 2017/08/18 02:13:59 by dcaudoux ### ########.fr */
  143. /* */
  144. /* ************************************************************************** */
  145.  
  146. #include <unistd.h>
  147. #include <stdio.h>
  148. #include <string.h>
  149.  
  150. void ft_putchar(char c);
  151.  
  152. void ft_putstr(char *str)
  153. {
  154. int i;
  155.  
  156. i = 0;
  157. while (str[i] != '\0')
  158. {
  159. ft_putchar(str[i]);
  160. i++;
  161. }
  162. }
  163.  
  164. int ft_strcmp(char *s1, char *s2)
  165. {
  166. int i;
  167.  
  168. i = 0;
  169. while (s1[i] || s2[i])
  170. {
  171. if (s1[i] != s2[i])
  172. return (s1[i] - s2[i]);
  173. i++;
  174. }
  175. return (0);
  176. }
  177.  
  178. int main(int argc, char **argv)
  179. {
  180. int i;
  181. char *tmp;
  182.  
  183. i = 1;
  184. while (i < argc - 1)
  185. {
  186. if (ft_strcmp(argv[i], argv[i + 1]) > 0)
  187. {
  188. tmp = argv[i];
  189. argv[i] = argv[i + 1];
  190. argv[i + 1] = tmp;
  191. i = 0;
  192. }
  193. i++;
  194. }
  195. i = 1;
  196. while (i < argc)
  197. {
  198. ft_putstr(argv[i]);
  199. ft_putchar('\n');
  200. i++;
  201. }
  202. return (0);
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement