Thread: can u assign structs to another

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    71

    can u assign structs to another

    ??

    for example

    if u have a struct, TEMP which consisted of 3 members

    1 int, 2 char pointers which were dynamically allocated (for strings)

    and this structure is inside another node (for instance a linked list)
    eg: NODE

    and u had a temporary TEMP struct (created locally) inside a function with some values

    can u do

    NODE x;

    x->temp = temp1;

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No. You can make a pointer point to a new structure (assuming it's dynamicly created or static, so it's not gone at the end of its scope), but you cannot do direct assignments, IIRC.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    71
    i hear ya mates
    thats exactly what i was thinking about and this other guy was having a debate with me about it
    so just wanted to confirm
    great example mate

    btw, that works as u mentioned
    just that the pointers store the addresses of the strings that were in the bar variable. once bar is gone, the struct still points successfully to the same place and strings remain

    but no one says its good programming style to have 2 pointers to the same place

    cheers mates

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multidimentional structs + memcpy() == FAIL
    By Viper187 in forum C Programming
    Replies: 8
    Last Post: 06-18-2008, 02:46 AM
  2. Generate Random Numbers and Assign to Days of Week
    By mms in forum C++ Programming
    Replies: 10
    Last Post: 05-04-2006, 01:51 AM
  3. Linked list question....again
    By dP munky in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2003, 05:59 PM
  4. packed structs
    By moi in forum C Programming
    Replies: 4
    Last Post: 08-20-2002, 01:46 PM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM