Unsinged char to int

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

  1. 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
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

  3. 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
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,236
    Martien Verbruggen
    Jun 27, 2003
  2. trey

    newbie: char* int and char *int

    trey, Sep 10, 2003, in forum: C Programming
    Replies:
    7
    Views:
    410
    Irrwahn Grausewitz
    Sep 10, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,680
    Old Wolf
    Jan 20, 2004
  4. lovecreatesbeauty
    Replies:
    1
    Views:
    1,097
    Ian Collins
    May 9, 2006
  5. gert
    Replies:
    20
    Views:
    1,194
Loading...

Share This Page