首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

结构体怎么排序。帮帮忙

2012-04-02 
结构体如何排序。。。帮帮忙#include stdio.h#include stdlib.hstructstudent{intidcharname[10]charse

结构体如何排序。。。帮帮忙
#include <stdio.h>
#include <stdlib.h>
struct   student
{
    int   id;
    char   name[10];
    char   sex[5];
    char   si[12];//sr=生日
    char   dz[100];//dz=地址
};
void   hello();
void   px(int   n);
void   main()
{
    hello();
    int   nums;
    printf( "请输入班级共几人?\n ");
    scanf( "%d ",&nums);
    struct   student   *   p;
    p=(struct   student   *)malloc(nums*sizeof(struct   student));
    for(int   i=0;i <nums;i++)
    {
        printf( "请按顺序输入学生   序号   姓名   性别   出生年月   地址\n ");
scanf( "%d   %s   %s   %s   %s ",&p[i].id,&p[i].name,&p[i].sex,&p[i].si,&p[i].dz);
    }
    for(int   j=0;j <nums;j++)
    {
        printf( "%d   %s   %s   %s   %s\n ",p[j].id,p[j].name,p[j].sex,p[j].si,p[j].dz);
    }
    int   temp=0;//这个temp我应该怎么定义????
    for(int   l=0;l <nums-2;l++)
    {
        for(int   m=0;m <nums-1;m++)
    if(p[m].id> p[m+1].id)
    {
    temp=p[m];//这里如何进行的???
    p[m]=p[m+1];
    p[m+1]=temp;
    }
    }

}
//////////hello//////////////
void   hello()
{
    printf( "**********************************\n ");
    printf( "*                                                                 *\n ");
    printf( "*     欢迎使用中科成绩评测系统             *\n ");
    printf( "*                                                                 *\n ");
    printf( "**********************************\n\n ");
}
///////////////////////////


大侠们给看看。。。

[解决办法]
出了什么问题??


int temp=0;//这个temp我应该怎么定义????
______________________________________________
struct student *temp;

热点排行