Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Unsinged char to int

Reply
Thread Tools

Unsinged char to int

 
 
Joseph Suprenant
Guest
Posts: n/a
 
      08-18-2003
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
 
Reply With Quote
 
 
 
 
Pieter Droogendijk
Guest
Posts: n/a
 
      08-18-2003
On 18 Aug 2003 06:08:52 -0700
http://www.velocityreviews.com/forums/(E-Mail Removed) (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#;+,)/'///*");}
 
Reply With Quote
 
 
 
 
Jan Engelhardt
Guest
Posts: n/a
 
      08-18-2003
>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[i] = chararray[i]; }

>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
int urldecode(char *src, char *last, char *dest) gert C Programming 20 02-16-2007 11:28 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
newbie: char* int and char *int trey C Programming 7 09-10-2003 03:24 AM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments