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')
字符串比较用strcmp方法,contacts这个是一个结构体变量,不是数组哦。应该是使用contacts.name,contacts.next.name访问:
contacts这个是一个结构体,不是结构体数组,所以contacts[i]这么写的时候就会报错。
而且,contacts这个结构体也没有初始化,你就使用了。
temp应该定义为int