Thread: Casting an array problem from unsigned int to uint8_t

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    50

    Casting an array problem from unsigned int to uint8_t

    Hi guys, Im facing a serious problem and I need your help please!
    what Im facing is that Im getting value from another function as integer
    which they are :
    Code:
    {5,1,2,3,4,5}
    so those value exactly I want to copy them to an array type uint8_t.
    this means the array that I want to get is
    Code:
    uint8_t arr={5,1,2,3,4,5};
    what actually the problem?
    the problem is this if I want to initialize and array type uint8_t with those values then I write immediately in the compiler:
    Code:
    uint8_t arr={5,1,2,4,5};
    (I mean by intilizing immediately ..once I write my syntax uint8_t arr in my compiler I write immediately
    Code:
    {5,1,2,3,4,5}
    )
    the problem that those values Im getting them from other function ..and I want those values to be entered as it's in an array type uint8_t this means my array would be the same with those value but type uint8_t =>
    Code:
    uint8_t arr={5,1,2,3,4,5};
    how can I do that ? I tried to use unsigned int and starting filling it with values
    Code:
     {5,1,2,3,4,5}
    but it didn't work!

    any help how can I implement that? thanks alot.

    what I mean by code is this:
    Code:
    int array2={5,1,2,3,4,5};
    unit8_t array1[6]={0};
    for(int i=0;i<(sizeof(array2)/sizeof(array2[0]));i++)
    {
    array1[i]=array[i];} /*I want the same values of array2 to enter to array1 but the type of array to be uint8_t*/
    }
    so what I expect to get once I print output is the array1 which it should be :
    Code:
     {5,1,2,3,4,5}
    and array1 type uint8_t with the same values that I copied them to it.

    but the output is wrong answer, it's���a��ߙ��I��

    any help please? thanks

    Last edited by Brian_Teir; 07-27-2020 at 11:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. casting clock_t to unsigned long
    By johnmerlino in forum C Programming
    Replies: 3
    Last Post: 04-19-2014, 11:28 AM
  2. Casting 0xFF (char) to 255 (unsigned int)
    By cyberfish in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2009, 11:21 AM
  3. Casting pointer to unsigned short
    By cks2k2 in forum C Programming
    Replies: 6
    Last Post: 03-25-2009, 05:33 AM
  4. Struct to Uint8_t array help please?
    By DavidDobson in forum C Programming
    Replies: 9
    Last Post: 01-20-2009, 08:17 AM
  5. int casting for unsigned chars
    By DarkMasterBosel in forum C++ Programming
    Replies: 4
    Last Post: 01-09-2008, 03:31 AM

Tags for this Thread