struct 使用
以 struct XXX{}形式定义结构体,结构体名为struct XXX,以typedef struct YY{}XXX形式定义结构体,结构体名字为XXX
使用struct XXX{}形式定义结构体
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
}Book2,*bookP;
/* function declaration */
void printBook( struct Books *book );
int main( ) {
struct Books Book1; /* Declare Book1 of type Book */
// struct book Book2; /* Declare Book2 of type Book */
/* book 1 specification */
strcpy( Book1.title, "C Programming");
strcpy( Book1.author, "Nuha Ali");
strcpy( Book1.subject, "C Programming Tutorial");
Book1.book_id = 6495407;
/* book 2 specification */
strcpy( Book2.title, "Telecom Billing