结构体的第一次

来源:互联网 发布:新疆2016年6月4g网络 编辑:程序博客网 时间:2024/05/16 06:50

我是一只很菜很菜的鸟,现已大二,可以说大一荒废了一年,现在竭力恶补以前的知识,今天第一次使用结构体。。。有本事才能有尊严,找到方向就得去努力,但是不知道有什么正确的方法,如果有大神路过,请指教。在此谢过。。


这是一个简单的学生管理系统,其实根本算不上系统,献丑啦。


/*2012年2月29日 00:58:02 结构体练习:学生管理系统*/ #include <stdio.h>#include <malloc.h>struct Student{char name[100];int age;float score;};void input(struct Student * ppArr, int lenth);void output(struct Student * ppArr, int lenth);struct Student sort(struct Student * ppArr, int lenth);int main(){int len;struct Student * pArr;printf("请输入学生人数:\n");printf("len = ");scanf("%d",&len);pArr = (struct Student *) malloc (len * sizeof(struct Student));input(pArr,len);sort(pArr,len);output(pArr,len);return 0;} void input(struct Student * ppArr, int lenth){int i;for(i=0;i<lenth;++i){printf("请输入第%d个学生的信息:\n",i+1);printf("name is ");scanf("%s",ppArr[i].name);printf("age = ");scanf("%d",&ppArr[i].age);printf("score = ");scanf("%f",&ppArr[i].score);}}void output(struct Student * ppArr, int lenth){int j;printf("\n\n学生的信息是:\n");for(j=0;j<lenth;++j){printf("第%d个学生的信息是:\n", j+1);printf("%s\n",ppArr[j].name);printf("%d\n",ppArr[j].age);printf("%f\n",ppArr[j].score);printf("\n");}}struct Student sort(struct Student * ppArr, int lenth){int p,q; struct Student t;for(p=0;p<lenth-1;++p){for(q=0;q<lenth-1-p;++q){if (ppArr[q].score > ppArr[q+1].score){t = ppArr[q];ppArr[q] = ppArr[q+1];ppArr[q+1] = t;}}}}