repositories
/
TD_C.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TP 13 exo2: Implement the missing bits to do a full game.
[TD_C.git]
/
TP_13
/
exo1
/
lib
/
io.c
diff --git
a/TP_13/exo1/lib/io.c
b/TP_13/exo1/lib/io.c
index 884d4a0b730f1d6e266628f326866a4e829112a2..69b13d768f2b68e4cd0a01e01f2e23ab30a8368a 100644
(file)
--- a/
TP_13/exo1/lib/io.c
+++ b/
TP_13/exo1/lib/io.c
@@
-1,9
+1,9
@@
+#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "io.h"
#include "array.h"
#include <stdio.h>
#include <stdbool.h>
#include "io.h"
#include "array.h"
-#include "utils.h"
int prompt_value(const char* msg, int* result) {
puts(msg);
int prompt_value(const char* msg, int* result) {
puts(msg);
@@
-50,7
+50,7
@@
void do_sort(int array[], unsigned size) {
int errno = 0;
int choice = 0;
bool done = false;
int errno = 0;
int choice = 0;
bool done = false;
-
criteria_cb
criteria;
+
s_criteria_cb sort_
criteria;
printf("\n=== Menu de tri ===\n\n");
printf("1) Croissant.\n");
printf("\n=== Menu de tri ===\n\n");
printf("1) Croissant.\n");
@@
-68,23
+68,23
@@
void do_sort(int array[], unsigned size) {
} while (!done);
switch (choice) {
case 1:
} while (!done);
switch (choice) {
case 1:
- criteria = ascending;
+
sort_
criteria = ascending;
break;
case 2:
break;
case 2:
- criteria = descending;
+
sort_
criteria = descending;
break;
case 3:
break;
case 3:
- criteria = ascending_and_even;
+
sort_
criteria = ascending_and_even;
break;
case 4:
break;
case 4:
- criteria = ascending_and_odd;
+
sort_
criteria = ascending_and_odd;
break;
default:
/* sort ascending by default, unused code path */
break;
default:
/* sort ascending by default, unused code path */
- criteria = ascending;
+
sort_
criteria = ascending;
break;
}
break;
}
- sort_tab(array, size, criteria);
+ sort_tab(array, size,
sort_
criteria);
}
void do_count(int array[], unsigned size) {
}
void do_count(int array[], unsigned size) {
@@
-102,10
+102,20
@@
void do_resize(int array[], unsigned* old_size) {
errno = prompt_value("\nNouvelle taille?", (int*)&new_size);
handle_prompt_error(errno);
errno = prompt_value("\nNouvelle taille?", (int*)&new_size);
handle_prompt_error(errno);
+ /* FIXME: one should able the set the array new content if new_size > *old_size
+ * for now, new values are zeroed */
array = resize_tab(array, *old_size, new_size);
*old_size = new_size;
}
array = resize_tab(array, *old_size, new_size);
*old_size = new_size;
}
+void handle_prompt_error(int errno) {
+ if (errno != 0) {
+ printf("\nMerci de saisir un nombre entier, exiting\n");
+ /* it's somewhat violent but better than looping forever */
+ exit(EXIT_FAILURE);
+ }
+}
+
void display_array(int array[], unsigned size) {
if (array != NULL) {
printf("\n--array begin--\n");
void display_array(int array[], unsigned size) {
if (array != NULL) {
printf("\n--array begin--\n");