summaryrefslogtreecommitdiff
path: root/011.c
diff options
context:
space:
mode:
Diffstat (limited to '011.c')
-rw-r--r--011.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/011.c b/011.c
new file mode 100644
index 0000000..4af029f
--- /dev/null
+++ b/011.c
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "input.h"
+
+#define INPUT "input/01.txt"
+
+int main() {
+ // lecture du fichier d'entree
+ FILE* file=fopen(INPUT,"r");
+ if(file == NULL) {
+ printf("Le fichier %s n'existe pas\n", INPUT);
+ return -1;
+ }
+ size_t lineCount = count_lines(file);
+ int* input = malloc(lineCount * sizeof(int));
+ if(read_lines_as_int(file, input, lineCount) != 0) {
+ printf("Erreur de parsing du fichier\n");
+ return -1;
+ }
+ // fermeture du fichier
+ fclose(file);
+
+ // calcul des variations de profondeur
+ int result = 0;
+ for(size_t i = 1; i < lineCount; i++) {
+ if(input[i] > input[i-1])
+ result++;
+ }
+ printf("%d\n", result);
+
+ return 0;
+}