Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
int* create_tab(int tab[], unsigned tab_size) {
tab = malloc(sizeof(int) * tab_size);
- if (tab == NULL) {
- return NULL;
- } else {
+ if (tab != NULL) {
/* initialize to zero the integer array */
for (unsigned i = 0; i < tab_size; i++) {
tab[i] = 0;
}
- return tab;
}
+ return tab;
}
void free_tab(int tab[]) {
int* resize_tab(int tab[], unsigned new_tab_size) {
tab = realloc(tab, sizeof(int) * new_tab_size);
- if (tab == NULL) {
- return NULL;
- } else {
- return tab;
- }
+ return tab;
}
/* number of occurences of an element in an unsorted array */
const unsigned tab_new_size = 20;
tab = resize_tab(tab, tab_new_size);
+ printf("%d\n", tab_new_size);
+
display_array(tab, tab_new_size);
free_tab(tab);