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 exo1: Implement a FIXME on array dynamic resizing
[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 69b13d768f2b68e4cd0a01e01f2e23ab30a8368a..b0a66a0fb1b14f4cc821a475c0a8558e9c90a44d 100644
(file)
--- a/
TP_13/exo1/lib/io.c
+++ b/
TP_13/exo1/lib/io.c
@@
-15,10
+15,10
@@
int* prompt_array(int array[], unsigned* size) {
int errno = prompt_value("Taille du tableau?", (int*)size);
array = create_tab(array, *size);
for (unsigned i = 0; i < *size; i++) {
int errno = prompt_value("Taille du tableau?", (int*)size);
array = create_tab(array, *size);
for (unsigned i = 0; i < *size; i++) {
- errno += prompt_value("Valeur?", &array[i]);
+ errno += prompt_value("Valeur?", &array[i]);
+ /* error might have occured */
+ handle_prompt_error(errno);
}
}
- /* error might have occured */
- handle_prompt_error(errno);
return array;
}
return array;
}
@@
-102,9
+102,14
@@
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);
array = resize_tab(array, *old_size, new_size);
+ if (new_size > *old_size) {
+ printf("Saisie des valeurs supplementaires du tableau\n");
+ for (unsigned i = *old_size; i < new_size; i++) {
+ errno += prompt_value("Valeur?", &array[i]);
+ handle_prompt_error(errno);
+ }
+ }
*old_size = new_size;
}
*old_size = new_size;
}