酸奶就算了吧,我更想喝酸梅汤或西瓜汁。
先写个简单的结构体吧,{姓名,成绩}两个数据成员
#include "stdio.h"
#define n 3
struct student {
char name[20];
int score;}
main()
{
struct student chengji[n];
int i;
for(i=0;i<n;i++)
{ printf("please enter an name:");
gets(chengji[i].name);
printf("please enter the score:");
gets(chengji[i].score);
}
for(i=0;i<n;i++)
{ printf("%s ",chengji[i].name);
printf("%d\n",chengji[i].score);
}
}
结构体的指针
#include "stdio.h"
#define n 3
struct student {
char name[20];
int score;}
main()
{
struct student chengji[n];
int i;
for(i=0;i<n;i++)
{ printf("please enter an name:");
gets(chengji[i].name);
printf("please enter the score:");
gets(chengji[i].score);
}
for(i=0;i<n;i++)
{ printf("%s ",chengji[i].name);
printf("%d\n",chengji[i].score);
}
struct student *pi;
pi =&chengji[0];
printf("the name is %s,the score is %d",pi->name,(*pi).score);
}