this is different from yours but It feel like the following
typedef int Item;
typedef struct da {
size_t s;//now size of array
Item *arr;//dynamic array
} Array;
Array *create(void){
Array *ap;
if((ap = malloc(sizeof(Array)))== NULL){
fprintf(stderr, "Array not created because no memory is available. \n");
} else {
fprintf(stderr, "Array created successfully. \n");
ap->s = 0;
ap->arr = NULL;
}
return ap;
}
bool is_equal(Item x, Item y){
return x == y;
}
bool is_element_of(Item x, Array *S){
size_t i;
for(i = 0; i < S->s ; ++i){
if(is_equal(x, S->arr[i]))
return true;
}
return false;
}
void add(Array *S, Item x){
if (is_element_of(x, S) == true){
fprintf(stderr, "Item already exists in array and therefore it can't be added. \n");
} else {
S->arr = realloc(S->arr, (S->s + 1) * sizeof(Item));
if(S->arr == NULL){
fprintf(stderr, "Memmory could not allocate.\n");
} else {
S->arr[S->s++] = x;
fprintf(stderr, "Item added successfully. \n");
}
}
}