C结构体指针的初步使用

#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\n",(*p1).title);//指针指向 (*p1).title  (*p1) = b1;
	printf("Books title:%s\n",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\n",p->name,p->xh,p->pinfo->info, p->pinfo->page);
	
	
	return 0;
}

  

posted @ 2018-03-14 10:07  王默默  阅读(536)  评论(0编辑  收藏  举报