Doubt regarding C structures and arrays. Quick suggestions please

This is a discussion on Doubt regarding C structures and arrays. Quick suggestions please within the C Programming forums, part of the General Programming Boards category; I have a doubt regarding C pointers, structures and arrays. Code: I have a structure typedef nx_struct DataMsg { nx_uint16_t ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    Doubt regarding C structures and arrays. Quick suggestions please

    I have a doubt regarding C pointers, structures and arrays.

    Code:
    I have a structure
    typedef nx_struct DataMsg {
    nx_uint16_t destID;
    nx_uint16_t sourceID;
    nx_uint16_t valueReported[100];
    } DataMsg;
    I have a variable named a .
    Code:
    a[100] ={100 values}
    I have a pointer created for a datapkt
    Code:
    DataMsg* datapkt = (DataMsg*) (call RadioPacket.getPayload(&radiopkt, NULL));
    i need to set the array of the structure to the value of a

    isnt this right
    Code:
    datapkt->valueReported = a; ?
    Gives me an error saying , invalid lvalue in assignment

    The data types mentioned above are similar to regular int

    An explanation would be good as well.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,456
    You cannot assign to an array, so you should use say, memcpy() instead.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2
    isnt there a concept of shallow copy in C?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,456
    Quote Originally Posted by cyrux
    isnt there a concept of shallow copy in C?
    If you are copying a pointer without copying what it points to, yes. But here you have an array, not a pointer.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. writing arrays of structures
    By chrismiceli in forum C Programming
    Replies: 6
    Last Post: 06-26-2003, 06:50 PM
  2. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  3. errors with arrays and structures
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2002, 10:48 PM
  4. Newbie Help (Arrays, Structures, Functions,Pointers)
    By tegwin in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 05:29 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21