Unsinged char to int

J

Joseph Suprenant

I have an array of unsigned chars and i would like them converted to
an array of ints. What is the best way to do this? Using RedHat 7.3
on an Intel Pentium 4 machine. Having trouble here, hope someone can
help
Thanks
 
P

Pieter Droogendijk

On 18 Aug 2003 06:08:52 -0700
I have an array of unsigned chars and i would like them converted to
an array of ints. What is the best way to do this? Using RedHat 7.3
on an Intel Pentium 4 machine. Having trouble here, hope someone can
help
Thanks

unsigned char srcarray[] = {1,2,3,4,5,6,7,8,9};
int arraysize = sizeof srcarray;
unsigned int dstarray[arraysze];

int elem;
for (elem=0; elem < arraysize; elem ++)
dstarray[elem] = srcarray[elem]

looks pretty pointless...
Can you post some approximation of what you want in the form of, say, source
code? I doubt this is it.
 
J

Jan Engelhardt

I have an array of unsigned chars and i would like them converted to
an array of ints.

int *ia = malloc(sizeof(int) * HowManyChars);
int i;
for(i = 0; i < HowManyChars; ++i) { ia = chararray; }
What is the best way to do this?

If not the above, then some library function will do it. Probably even better,
since libc will -- probably -- use assembly, which is the fastest.
Using RedHat 7.3 on an Intel Pentium 4 machine.
Doesnot matter. Your question is relevant for all OS.
Having trouble here, hope someone can
If it's not related, nobody cares.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top