aboutsummaryrefslogtreecommitdiff
path: root/exam_final/rendu/ord_alphlong/helper2.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-26 23:17:36 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-26 23:17:36 +0200
commit8ec5431354bdb582455e8c32758098c5a0fdada2 (patch)
tree480c68814f822439850029df0e0249a2cafb8177 /exam_final/rendu/ord_alphlong/helper2.c
parent475449dd4b1f3308bac6f72c34d87812216a0738 (diff)
downloadpiscine-8ec5431354bdb582455e8c32758098c5a0fdada2.tar.gz
piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.tar.bz2
piscine-8ec5431354bdb582455e8c32758098c5a0fdada2.zip
exam final
Diffstat (limited to 'exam_final/rendu/ord_alphlong/helper2.c')
-rwxr-xr-xexam_final/rendu/ord_alphlong/helper2.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/exam_final/rendu/ord_alphlong/helper2.c b/exam_final/rendu/ord_alphlong/helper2.c
new file mode 100755
index 0000000..431274b
--- /dev/null
+++ b/exam_final/rendu/ord_alphlong/helper2.c
@@ -0,0 +1,77 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* helper2.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: exam <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/26 15:20:07 by exam #+# #+# */
+/* Updated: 2019/07/26 16:29:42 by exam ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "include.h"
+
+int sorted(char **strs, int cmp(char*, char*))
+{
+ int i;
+
+ i = 0;
+ if (strs[0] == NULL)
+ return (1);
+ while (strs[i + 1] != NULL)
+ {
+ if ((*cmp)(strs[i], strs[i + 1]) > 0)
+ return (0);
+ i++;
+ }
+ return (1);
+}
+
+void sort_strs(char **strs, int cmp(char*, char*))
+{
+ int i;
+ char *tmp;
+
+ while (!sorted(strs, cmp))
+ {
+ i = 0;
+ while (strs[i + 1] != NULL)
+ {
+ if ((*cmp)(strs[i], strs[i + 1]) > 0)
+ {
+ tmp = strs[i];
+ strs[i] = strs[i + 1];
+ strs[i + 1] = tmp;
+ }
+ i++;
+ }
+ }
+}
+
+int strlen_cmp(char *s1, char *s2)
+{
+ return (ft_strlen(s1) - ft_strlen(s2));
+}
+
+void print_strs(char **strs)
+{
+ int i;
+ int len;
+
+ i = 0;
+ while (strs[i] != NULL)
+ {
+ len = ft_strlen(strs[i]);
+ while (strs[i] && ft_strlen(strs[i]) == len)
+ {
+ ft_putstr(strs[i]);
+ if (strs[i + 1] != NULL && ft_strlen(strs[i + 1]) == len)
+ ft_putstr(" ");
+ else
+ ft_putstr("\n");
+ i++;
+ }
+ }
+}