array of structures

This is a discussion on array of structures within the C Programming forums, part of the General Programming Boards category; I can't figure out how to access data members in an array of structures to store data. Here is my ...

  1. #1
    cwd
    cwd is offline
    Registered User
    Join Date
    Sep 2001
    Posts
    9

    Angry array of structures

    I can't figure out how to access data members in an array of structures to store data.
    Here is my program:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    struct drivers_license
    {
    char lastname[10];
    char firstname[10];
    int licensenumber[8];
    char statecode[2];
    struct address;
    int height;
    char eyecolor[8];
    char haircolor[8];
    struct vehicle;
    char visioncode[10];
    int birthdate[3];
    int expirationdate[3];
    char organdonor[3];
    };

    struct address
    {
    int streetnumber[5];
    char streetname[10];
    int aptnumber[5];
    char city[10];
    char state[10];
    int zipcode[5];
    };

    struct vehicle
    {
    char motorcycle;
    char automobile;
    char schoolbus;
    char commericaltruck;
    char semitrailer;
    };

    void records(struct drivers_license *record[15]);
    void changes(struct drivers_license *record[15]);

    int main()
    {
    struct drivers_license *record[15];
    return 0;
    }

    void records(struct drivers_license *record[15])
    {
    record[0]->lastname[10]="Smith/0";
    }

    void changes(struct drivers_license *record[15])
    {
    }

    when I compile it, it comes up with an error, saying cannot convert char * to char

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    struct mystruct myarray[3];

    myarray[1].myvariable = 30;


    > void records(struct drivers_license *record[15])
    > {
    > record[0]->lastname[10]="Smith/0";
    > }

    This is wrong. You cannot simply assign values like this. Additionally, you do not put a null in a string, it automaticly includes one.
    Code:
    void record( struct drivers_license record[] )
    {
       sprintf( record[0].lastname, "Smith" );
    }
    Quzah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-06-2006, 12:06 AM
  2. filling an array of structures?
    By voodoo3182 in forum C Programming
    Replies: 9
    Last Post: 08-06-2005, 06:29 PM
  3. Array of Structures: Sorting
    By Drainy in forum C Programming
    Replies: 3
    Last Post: 04-13-2005, 10:55 AM
  4. Filling an Array of Structures
    By Zildjian in forum C Programming
    Replies: 5
    Last Post: 11-12-2003, 05:54 PM
  5. Need serious help on array of structures
    By cwd in forum C Programming
    Replies: 2
    Last Post: 11-11-2001, 03:39 PM

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