structures why

Discussion in 'C Programming' started by Darklight, May 20, 2004.

  1. Darklight

    Darklight Guest

    why does this not work

    i get the error initialize1.c:13: error: two or more data types in
    declaration of `mysale'

    example below taken from book, "it says in the book"
    For a structure that contains structures as members, list the initialisation
    values in order. They are placed in the structure members in the order in
    which the members are listed in the structure definition. Here's an example
    to explain it

    /* INITIALIZE1.C */
    #include<stdio.h>

    struct customer{
    char firm[20];
    char contact[25];
    }

    struct sale{
    struct customer buyer;
    char item[20];
    float amount;
    }mysale = { {"acme Industries", "George Adams"}, /* line 13 */
    "left_hand widget",
    1000.00
    };

    int main(void) /* this bit add by me just to see it work */
    {
    printf("%s\n%s\n",mysale.buyer.firm,mysale.buyer.contact);
    printf("%s\n%f\n",mysale.item, mysale.amount);
    return 0;
    }
    Darklight, May 20, 2004
    #1
    1. Advertising

  2. Darklight

    Darklight Guest

    Darklight wrote:


    struct customer{
    char firm[20];
    char contact[25];
    }

    sorry to waste your time the book had a typing error there
    should be a semi colon after the brace: as below

    struct customer{
    char firm[20];
    char contact[25];
    };
    Darklight, May 20, 2004
    #2
    1. Advertising

  3. Darklight wrote:
    > why does this not work
    >
    > i get the error initialize1.c:13: error: two or more data types in
    > declaration of `mysale'

    [...]
    > struct customer{
    > char firm[20];
    > char contact[25];
    > }

    ^^^ missing semicolon
    Martin Ambuhl, May 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darklight

    structures why

    Darklight, May 23, 2004, in forum: C Programming
    Replies:
    4
    Views:
    331
    Darklight
    May 24, 2004
  2. tweak
    Replies:
    14
    Views:
    2,781
    Eric Sosman
    Jun 11, 2004
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    880
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,849
    Smokey Grindel
    Dec 2, 2006
  5. Alfonso Morra
    Replies:
    11
    Views:
    713
    Emmanuel Delahaye
    Sep 24, 2005
Loading...

Share This Page