C language: Implementation of dynamic array initialization, insertion, traversal, deletion and destruction

Initialization of dynamic array

#include <iostream>
using namespace std;
struct dynamicArray{ 
      void **pAddr;
      int m_capacity;
      int m_size;
      }
struct dynamicArray *initdynamicArray(int capacity){ 
         if(capacity<=0) {      
           return 0;
           }  
   struct dynamicArray *array=malloc(sizeof(struct dynamicArray)) 
   if(array=NULL){   
      return 0;
    }   
     array->pAddr=malloc(sizeof(void*)*capacity); 
     array->m_capacity=capacity;   
     array->size=0;    
     return array;
     }

Function series

```void *insert(struct dynamicArray *array,int pos,void *data){
if(array==NULL||data==NULL){
    return 0;
}
if(pos<=0||pos>array->m_size){
     pos=array->m_size;
}
if(array->m_size==array->capacity){
     int newCapacity=array->capacity;
     void **newSpace=malloc(sizeof(void*)*newCapacity);
     memcpy(newSpace,array->pAddr,sizeof(void *)*array->capacity);
     free(array->pAddr);
     array->pAddr=newSpace;
}

for(int i=array->m_size;i<=pos;i--){
     array->pAddr[i+1]=array->pAddr[i];
}

array->pAddr[pos]=data;

void foreach_Dynamicarray(struct dynamicArray *array,void(myPrint)(void*)){
     for(int i=0;i<array->m_size;i++){
     myPrint(array->pAddr[i]);
     }
 }
 void myPrintPerson(void *data){
     struct person *p=data;
     cout<<p->blabla<p->blabuble<endl;
 }

 void remove(struct dynamicArray *array,int pos){
     if(array==NULL||pos<=0||pos>=array->){
      return 0;
   }
   for(int i=array->m_size;i>=pos;i--){
       array->pAddr[i]=array->pAddr[i+1];
   }
 }

 void destroy(struct dynamicArray *array){
    if(array=NULL){
        return 0;
    }
    if(array->pAddr!=NULL){
        free(array->pAddr);
        array->pAddr=NULL;
    }
    free(array);
    array=NULL;
 }


Read More: