1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <stdio.h> #include <string.h>
#define MAXTITL 41 #define MAXAUTL 31 #define MAXBOOK 10
struct book { char title[MAXTITL]; char author[MAXAUTL]; float value; };
int main(int argc, char *argv[]) { struct book crusoe; strcpy(crusoe.title, "鲁滨逊漂流记"); strcpy(crusoe.author, "迪福"); crusoe.value = 66.66; printf("book crusoe,title: %s ,author: %s , value:%f \n", crusoe.title, crusoe.author, crusoe.value); struct book stone= { "红楼梦", "雪里红芹菜", 100.00 }; printf("book stone,title: %s ,author: %s , value:%f \n", stone.title, stone.author, stone.value); struct book piao = { .author = "斯嘉丽", .title = "乱世佳人", .value = 22.22 }; printf("book piao,title: %s ,author: %s , value:%f \n", piao.title, piao.author, piao.value); struct book library[MAXBOOK]; library[0] = crusoe; library[2] = stone; library[3] = piao; printf("sizeof struct book is %d , sizeof library is %d \n", sizeof(stone), sizeof(library)); return 0; }
|