c - How to scan values into an array using a generic void pointer? -


given method header

void scanarray(void *arr, int const numelements, int const sizeelement, char const *fmt) 

where *arr can type of array, numelements number of elements in array, , sizeelement size of type of value in array, , fmt string such %d, %lf, or %f, how write function uses scanf insert values array?

void scanarray(void *arr, int const numelements, int const sizeelement, char const *fmt){   int i;   unsigned char *temparr = (unsigned char*) arr;   for(i=0; i<numelements; i++, temparr+=sizeelement) scanf(fmt, temparr); } 

this seems working me...


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -