结构体的设置比较简单,但注意:
为了使用指向该结构的指针访问结构的成员,您必须使用 -> 运算符,如下所示:
struct_pointer->title;
具体实现代码如下:
#include<stdio.h>
#include<string.h>
struct Books{
char title[50];
char author[30];
char subject[100];
int bookId;
};
void printBook(struct Books *book);
int main(){
struct Books book1;
strcpy(book1.title,"science");
strcpy(book1.author,"AaronChen");
strcpy(book1.subject,"technology");
book1.bookId=11;
printBook(&book1);
return 0;
}
void printBook(struct Books *book){
printf("%s\n",book->title);
printf("%s\n",book->author);
printf("%s\n",book->subject);
printf("%d\n",book->bookId);
}