struct Student
{
int ID;
char Name[10];
};
void sort(Student *a, int n)
{
Student t;
int i, j;
for(i=0;i
{
memcpy(&t, &a[j], sizeof(Student));
memcpy(&a[j], &a[j+1], sizeof(Student));
memcpy(&a[j+1], &t, sizeof(Student));
}
}
在结构体赋值中,上面使用memcpy函数,如:
memcpy(&t, &a[j], sizeof(Student));
可以替换为:
t.ID = a[j].ID;
strcpy(t.Name, a[j].Name);
依次类推。