01-preliminaries/preliminaries.cpp
void print_array(void *x,int nElems,enum data_types dt)
{
    printf("\n");
    for(int i = 0 ; i < nElems ; i++)
    {        
        switch(dt)
        {
            case chr :
            {
                    char *c = (char *)x;                    
                    printf("%c ",c[i]);
                    break;
            }
            case intg :
            {
                    int *g = (int *)x;                    
                    printf("%d ",g[i]);
                    break;
            }
            case flt :
            {
                    float *f = (float *)x;                    
                    printf("%f ",f[i]);
                    break;
            }
            case dbl:
            {
                    double *d = (double *)x;                    
                    printf("%lf ",d[i]);
                    break;
            }
        }
    }
    printf("\n");
}
// An ugly, but generic way of printing an array of in-built data types
An ugly, but generic way of printing an array of in-built data types
An ugly but generic way of printing an array of in - built data types
void print_array(void *x,int nElems,enum data_types dt)
{
    printf("\n");
    for(int i = 0 ; i < nElems ; i++)
    {        
        switch(dt)
        {
            case chr :
            {
                    char *c = (char *)x;                    
                    printf("%c ",c[i]);
                    break;
            }
            case intg :
            {
                    int *g = (int *)x;                    
                    printf("%d ",g[i]);
                    break;
            }
            case flt :
            {
                    float *f = (float *)x;                    
                    printf("%f ",f[i]);
                    break;
            }
            case dbl:
            {
                    double *d = (double *)x;                    
                    printf("%lf ",d[i]);
                    break;
            }
        }
    }
    printf("\n");
}
void print_array ( void * x , int nElems , enum data_types dt ) { printf ( " \n " ) ; for ( int i = 0 ; i < nElems ; i ++ ) { switch ( dt ) { case chr : { char * c = ( char * ) x ; printf ( " " , c [ i ] ) ; break ; } case intg : { int * g = ( int * ) x ; printf ( " " , g [ i ] ) ; break ; } case flt : { float * f = ( float * ) x ; printf ( " " , f [ i ] ) ; break ; } case dbl : { double * d = ( double * ) x ; printf ( " " , d [ i ] ) ; break ; } } } printf ( " \n " ) ; }
An ugly, but generic way of printing an array of in-built data types
An ugly but generic way of printing an array of in - built data types