structures why

D

Darklight

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;
}
 
D

Darklight

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];
};
 
M

Martin Ambuhl

Darklight said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top