Ch10-Structure C-Style
Ch10-Structure C-Style
FSC1331/FDN1120
Topic 10 : Structure (C-Style Struct)
17/01/2016 1
10.1 Structures
17/01/2016 2
10.1.1 Definitions and Declarations
17/01/2016 3
10.1.1 Definitions and Declarations
17/01/2016 4
10.1.1 Definitions and Declarations
17/01/2016 5
10.1.1 Definitions and Declarations
17/01/2016 7
10.2 Accessing Structures
17/01/2016 8
10.2 Accessing Structures
17/01/2016 9
10.3 Arrays of Structures
17/01/2016 10
10.3 Arrays of Structures
17/01/2016 11
10.4 Sample Programs
17/01/2016 12
10.4 Sample Programs
17/01/2016 13
10.4 Sample Programs
null terminating
character
17/01/2016 14
#include <stdio.h>
/* print Book1 info */
#include <string.h>
printf( "Book 1 title : %s\n", Book1.title);
printf( "Book 1 author : %s\n", Book1.author);
struct Books {
printf( "Book 1 subject : %s\n", Book1.subject);
char title[50];
printf( "Book 1 book_id : %d\n", Book1.book_id);
char author[50];
/* print Book2 info */
char subject[100];
printf( "Book 2 title : %s\n", Book2.title);
int book_id; };
printf( "Book 2 author : %s\n", Book2.author);
printf( "Book 2 subject : %s\n", Book2.subject);
int main( )
printf( "Book 2 book_id : %d\n", Book2.book_id);
{
return 0;
struct Books Book1;
}
struct Books Book2;