作者在 2011-05-04 10:49:19 发布以下内容
今天学习了结构,感觉它的效果不错。
#include "stdafx.h"
struct Student
{ int id; // int域
char name[10];
double score;
};
void Print(Student ss[],int n);
int main(int argc, char* argv[])
{
Student s1;
s1.id=1; strcpy(s1.name,"aaa"); s1.score=99.9;
Student s2={2,"bbb",98.9};
printf("%d,%s,%lf\n",s1.id,s1.name,s1.score);
printf("%d,%s,%lf\n",s2.id,s2.name,s2.score);
Student ss[3];
ss[0].id=101; strcpy(ss[0].name,"xx"); ss[0].score=91;
ss[1].id=102; strcpy(ss[1].name,"yy"); ss[1].score=92;
ss[2].id=103; strcpy(ss[2].name,"zz"); ss[2].score=93;
Print(ss,3);
return 0;
}
void Print(Student ss[],int n)
{
// for(int i=0; i<n; i++)
// printf("%d,%s,%lf\n",ss[i].id,ss[i].name,ss[i].score);
Student *p;
p=ss;
while(p<ss+n)
{
//printf("%d,%s,%lf\n",(*p).id,(*p).name,(*p).score);
printf("%d,%s,%lf\n",p->id,p->name,p->score);
p++;
}
}
struct Student
{ int id; // int域
char name[10];
double score;
};
void Print(Student ss[],int n);
int main(int argc, char* argv[])
{
Student s1;
s1.id=1; strcpy(s1.name,"aaa"); s1.score=99.9;
Student s2={2,"bbb",98.9};
printf("%d,%s,%lf\n",s1.id,s1.name,s1.score);
printf("%d,%s,%lf\n",s2.id,s2.name,s2.score);
Student ss[3];
ss[0].id=101; strcpy(ss[0].name,"xx"); ss[0].score=91;
ss[1].id=102; strcpy(ss[1].name,"yy"); ss[1].score=92;
ss[2].id=103; strcpy(ss[2].name,"zz"); ss[2].score=93;
Print(ss,3);
return 0;
}
void Print(Student ss[],int n)
{
// for(int i=0; i<n; i++)
// printf("%d,%s,%lf\n",ss[i].id,ss[i].name,ss[i].score);
Student *p;
p=ss;
while(p<ss+n)
{
//printf("%d,%s,%lf\n",(*p).id,(*p).name,(*p).score);
printf("%d,%s,%lf\n",p->id,p->name,p->score);
p++;
}
}