#include<stdio.h>#include<string.h>#include<stdlib.h>struct dog{char*name;int weight;char*color;};voiddisplay(struct dog *n);intmain(){struct dog m;/*
下面两行缺一不可,
如果不想要这两行可以把
结构体改为 struct dog{
char name[100];
int weight;
char color[100];
};
*/
m.name=(char*)malloc(200*sizeof(char));
m.color=(char*)malloc(200*sizeof(char));
m.weight=30;strcpy(m.name,"ahuang");strcpy(m.color,"yellow");display(&m);return0;}voiddisplay(struct dog *n){printf("%s is %d and it is %s",n->name,n->weight,n->color);}