Thread: having probs with array structures

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    54

    having probs with array structures

    okay heres my code

    struct vector
    {
    char dataList[27];
    };



    int main(void)
    {
    struct vector listItem[10];

    addData(listItem, data);

    .
    .
    .
    }




    void addData(struct vector listItem[10], char data[27])
    {
    *listItem[index]->dataList = data;//why does this code not work, at present i get pointer to structure error message

    *listItem[index].dataList = data;//this way gives me a lvalue error message

    //any help will be greatly appreciated
    }


    i removed some of the code to keep the post size down

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    listitem is a struct vector *
    listitem[index] is a struct vector
    listitem[index].dataList is a char *
    * listitem[index].datalist is a char

    listitem[index] -> datalist doesn't mean anything, since listitem[index] isn't a struct *

    data is a char *

    * listitem[index].datalist = data
    tries to put a char * value into a char. Try using a string copy command instead.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    If you're using indexes to access the elements then you don't need to use pointer notation, and if you're coping strings you'll need to use strcpy() -

    strcpy(listItem[index].dataList,data);
    zen

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    54

    wooohoooo

    hehe, thanx guys, thats got me back on course again

    that one had me stumped for a couple of days, i thought i had tried everything aswell

    thanx again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2008, 10:25 AM
  2. filling an array of structures?
    By voodoo3182 in forum C Programming
    Replies: 9
    Last Post: 08-06-2005, 05:29 PM
  3. array of structures help!
    By voodoo3182 in forum C Programming
    Replies: 12
    Last Post: 08-03-2005, 02:58 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Need serious help on array of structures
    By cwd in forum C Programming
    Replies: 2
    Last Post: 11-11-2001, 03:39 PM