琳琳在哪 2021-12-29 09:34 采纳率: 100%
浏览 1393
已结题

[Error] no match for 'operator[]' (operand types are 'contacts' and 'int')

问题遇到的现象和发生背景
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')

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

3条回答 默认 最新

  • 关注

    字符串比较用strcmp方法,contacts这个是一个结构体变量,不是数组哦。应该是使用contacts.name,contacts.next.name访问:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 1月6日
  • 已采纳回答 12月29日
  • 创建了问题 12月29日

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示