- //结构体指针
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>//分配空间
- typedef struct person
- {
- int age;
- int height;
- char name[15];
- int weight;
- } Person;
- int main()
- {
- Person *pp =(Person *)malloc(sizeof(struct person));//建议强制转换
- memset(pp, 0, sizeof(Person));
- printf("Please input your name:");
- scanf("%s", pp->name);
- printf("Please input your height:");
- scanf("%d", &pp->height);
- printf("Please input your age:");
- scanf("%d", &pp->age);
- printf("Please input your weight:");
- scanf("%d", &pp->weight);
- printf("name:%s\\nheight:%d\\nage:%d\\nweight:%d",pp->name, pp->height, pp->age, pp->weight);
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0906201512825.html
来源: http://www.codesnippet.cn/detail/0906201512825.html