问题遇到的现象和发生背景
void sort()//显示所有联系人(按姓名排序)
{
struct contacts *n;
struct contacts contacts;
struct contacts temp;
int i;
for(i=0;i<100;i++)
{
if(contacts[i].name>contacts[i+1].name)
temp=contacts[i].name;
contacts[i].name=contacts[i+1].name;
contacts[i+1].name=temp;
}
for(n=head->next;n->next!=NULL;n=n->next)
{
printf("姓名\t性别\t出生日期\t单位\t邮编\t通信地址\t电话\tE-mail\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",n->name,n->sex,n->birth,n->work,n->youbian,n->add,n->tel,n->email);
}
}
问题相关代码,请勿粘贴截图
if(contacts[i].name>contacts[i+1].name)
temp=contacts[i].name;
contacts[i].name=contacts[i+1].name;
contacts[i+1].name=temp;
运行结果及报错内容
[Error] no match for 'operator[]' (operand types are 'contacts' and 'int')