#include<stdio.h>
#include<stdlib.h>
struct student
{
char num;
char name[10];
int grade;
};
void swap(struct student *p[],int n)
{
int k,m,i,j;
struct student *d;
k=0;m=n-1;
while(k<m)
{
j=m-1;m=0;
for(i=k;i<=j;i++)
if(((*p[i]).grade)>((*p[i+1]).grade))
{d=p[i];p[i]=p[i+1];p[i+1]=d;m=i;}
j=k+1;k=0;
for(i=m;i>=j;i--)
if(((*p[i-1]).grade)>((*p[i]).grade))
{d=p[i];p[i]=p[i-1];p[i-1]=d;k=i;}
}
return;
}
main()
{
int i;
struct student *q[13];
struct student h[13]=
{
{2,"Lin",92},
{3,"Zhang",87},
{4,"Zhao",72},
{5,"Ma",91},
{9,"Zhen",85},
{11,"Wang",100},
{12,"Li",86},
{13,"Xu",83},
{16,"Mao",78},
{17,"Hao",95},
{20,"Lu",82},
{21,"Song",76},
{22,"Wu",88}
};
for(i=0;i<13;i++)
** *q[i]=h[i];**
printf("学号(num) 姓名(name) 成绩(grade)\n");
for(i=0;i<13;i++)
printf(" %02d %s %d\n",h[i].num,h[i].name,h[i].grade);
printf("------------------------------\n");
swap(q,13);
for(i=0;i<13;i++)
printf(" %02d %s %d\n",(*q[i]).num,(*q[i]).name,(*q[i]).grade);
}
0x00BB16B0 处有未经处理的异常: 0xC0000005: 写入位置 0xCCCCCCCC 时发生访问冲突。(代码中加粗的行: *q[i]=h[i];),这是为什么呢?