#include <stdio.h> #include <string.h> struct Books { char title[50]; //char author[100]; //int book_id; }; int main(){ struct Books b1; strcpy(b1.title,"C语言"); struct Books *p1; p1 = &b1; strcpy(p1->title,"Java 语言!"); printf("Books title:%s ",(*p1).title);//指针指向 (*p1).title (*p1) = b1; printf("Books title:%s ",b1.title); return 0; }
#include <stdio.h> #include <string.h> struct bookinfo { char *info; char *page; }; struct Books { char *name; int xh; struct bookinfo *pinfo; }; int main(){ struct bookinfo binfo = {"产地深圳","900"}; struct Books b1 = { "C语言",100,&binfo }; /*定义结构体指针*/ struct Books *p = &b1; printf("name:%s xh:%d info:%s page:%s ",p->name,p->xh,p->pinfo->info, p->pinfo->page); return 0; }