怎么用指针将整个结构的数据对换

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:39:38
struct staffs
{int n,id;
char name[20];

}staff[50];在用指针排序的时候。。怎么将staff[1]与staff[0]的里面的全部数据对换呢?不要数组排,是指针,谢谢。
其实两个都用了数组。。。

可以这样
struct staffs
{int n,id;
char name[20];
}*staff[50];
for (int i=0; i<50; i++)
{
staff[i] = new struct staffs;
}

struct staffs *p;
p = staff[0];
staff[0] = staff[1];
staff[1] = p;

staffs temp;
temp = staff[0];
staff[0] = staff[1];
staff[1] = temp;

什么叫数组,你是说不能用staff[0],staff[1]这样的描述?这是一个结构常量,根本不明白你的目的.