# Unsinged char to int

Discussion in 'C Programming' started by Joseph Suprenant, Aug 18, 2003.

1. ### Joseph SuprenantGuest

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

Joseph Suprenant, Aug 18, 2003

2. ### Pieter DroogendijkGuest

On 18 Aug 2003 06:08:52 -0700
(Joseph Suprenant) wrote:
> 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.

--
char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
c,k,0),x(c,k+=*s-c,s+1),*k)x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh\$%c","-34*1'.+(,03#;+,)/'///*");}

Pieter Droogendijk, Aug 18, 2003

3. ### Jan EngelhardtGuest

Re: Unsigned char to int

>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.

--
- Jan Engelhardt

Jan Engelhardt, Aug 18, 2003