There is far too much code to post, I posted the main bits of the program which are relevant. Here is citizens code which I modified slightly and prints out wierd output:
Code:
#include <stdio.h>
#include <stdlib.h>
#define MIN_SIZE 10U
int *append( int *parray[], size_t size, int anynum );
int main(void) {
int i = 0;
int *test = malloc(MIN_SIZE * sizeof *test);
if (test) {
int fill;
for (fill = 0; fill < MIN_SIZE; ++fill) {
test[fill] = fill + 1;
}
/*
** Checking appends return value to make sure that everything worked
*/
if (append(&test, MIN_SIZE, 11) != NULL) {
}
else {
printf("Failure :(\n");
}
for(i=0;i<fill;i++){
printf("%d ",test[i]);
}
free(test);
}
else {
perror("malloc");
}
return 0;
}
int *append( int *parray[], size_t size, int anynum ) {
int *newarray = realloc(*parray, size + 1U);
if (newarray) {
*parray = newarray;
(*parray)[size] = anynum;
}
else {
free(newarray);
newarray = NULL;
}
return newarray;
}