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

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -