|
发表于 2005-5-31 16:54:31
|
显示全部楼层
#include "string.h"
#include "memory.h"
#define COUNT 5
#define NAME_LEN 20
typedef struct student{
unsigned int number;//学号
unsigned char mark;//分数
char name[NAME_LEN];//应该够用了吧
}STUDENT;
void sort(STUDENT *lpstudent)
{
int i;
int j;
STUDENT Tmp;
for(i=0; i<COUNT; ++i){
for(j=i+1; j<COUNT; ++j){
if(lpstudent.mark > lpstudent[j].mark){
Tmp.number = 0;
Tmp.mark = 0;
memset(Tmp.name, 0, NAME_LEN);
Tmp.number = lpstudent[j].number;
Tmp.mark = lpstudent[j].mark;
strncpy(Tmp.name, lpstudent[j].name, NAME_LEN);
lpstudent[j].number = lpstudent.number;
lpstudent[j].mark = lpstudent.mark;
strncpy(lpstudent[j].name, lpstudent.name, NAME_LEN);
lpstudent.number = Tmp.number;
lpstudent.mark = Tmp.mark;
strncpy(lpstudent.name, Tmp.name, NAME_LEN);
}
}
}
}
int main(int argc, char* argv[])
{
int i;
STUDENT s_array[COUNT] = {{0,0,},};
printf("请按先后顺序输入学号,分数,姓名\n");//判断留个楼主了
for(i=0; i<COUNT; ++i){
printf("共有%d个学生,下面输入第%d个\n",COUNT,i+1);
printf("请输入学号:");
scanf("%d",&s_array.number);
printf("请输入分数:");
scanf("%d",&s_array.mark);
printf("请输入姓名:");
scanf("%s",s_array.name);
}
printf("下面排序:\n");
sort(s_array);
printf("下面输出:\n");
for(i=0; i<COUNT; ++i){
printf("%d------ 学号:%d 分数:%d 姓名:%s\n",i+1,s_array.number,s_array.mark,s_array.name);
}
return 0;
}
还有很多工作要做!没时间了!
比如判断输入的分数是否在范围之内!
目前输入分数必须是整数等等,这些留个楼主做吧!
很可惜,编译环境是vc 6。我这没有linux |
|