int* resize_tab(int tab[], unsigned old_tab_size, unsigned new_tab_size) {
tab = realloc(tab, sizeof(int) * new_tab_size);
+ /* zero by default the added cells */
if (old_tab_size < new_tab_size) {
for (unsigned i = old_tab_size; i < new_tab_size; i++) {
tab[i] = 0;
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;
}
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);
+ 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;
}