c - Conversion from unsigned int array to unsigned char array -
i don't know how convert array of unsigned int array of unsigned char in way. receive suggestions.
to more clear, problem have function read memory putting data in unsigned int array. want data , convert unsigned char put in, example, serial port.
thanks
you either use uint array element element
for (i=0 ; i<arraylength ; i++) processuchar((unsigned char) uintarray[i]);
or create new array , copy elements
unsigned int uintarray[n]; unsigned char uchararray[n]; (i=0 ; i<n ; i++) uchararray[i] = (unsigned char)uintarray[i];
and utilize new uchararray array.
or prefer dynamically allocate new array, before copy
unsigned char *uchararray = malloc(sizeof(unsigned char) * n); (i=0 ; i<n ; i++) uchararray[i] = (unsigned char)uintarray[i];
in case (dynamic) you'll have free array when don't need anymore
free (uchararray);
Comments
Post a Comment