如何在分类结构C中使用数组类型误差将分配固定到表达式C

发布于 2025-02-08 19:39:25 字数 1488 浏览 2 评论 0原文

当我尝试比较指向结构的指针时,如何修复“使用数组类型的分配到表达式”。我想通过使用条件要求用户选择他们想根据给定选择对用户数据进行分类,从而根据所选列(例如活动)对用户数据进行排序。然后,我想运行程序,然后出现问题。

这是我的代码结构:

struct fitnessTracking {
    char activity[50], unit[50];
    int calories;
    float total, weight, height, bmi;
};
struct recordDate {
    int dd, mm, yyyy;
    int duration;
};
struct user {
    char username[50];
    struct fitnessTracking tracker;
    struct recordDate record;
};

struct Number {
    struct Number *ptrnext;
    struct user member;
};

struct Number *newptr, *currentptr;

这是我的活动排序函数:

void activitySort(struct Number *head){
    struct Number *temp = NULL; struct Number *ptr=NULL;
    currentptr = head;

    if(head == NULL)
        return;

    while(currentptr != NULL){ //while current pointer not null
        ptr = currentptr->ptrnext;
        while(ptr != NULL){
            if(currentptr->member.tracker.activity > ptr->member.tracker.activity){
                temp = currentptr->member.tracker.activity;
                currentptr->member.tracker.activity = ptr->member.tracker.activity;
                ptr->member.tracker.activity = temp;
            }ptr = ptr->ptrnext;
        }currentptr=currentptr->ptrnext;
    }
}

带有错误代码错误的这2行上的错误:用数组类型 reform 分配给表达式

currentptr->member.tracker.activity = ptr->member.tracker.activity;
ptr->member.tracker.activity = temp;

我该如何修复它们?

How can I fix the error "assignment to expression with array type" when I try to compare the pointer that point to the structure. I want to sort the user data based on the selected column (e.g. activity) by using a condition to ask users to choose they want to sort the user data based on the given choice. Then after that, I want to run the program then the problems appear.

Here is my structure of my codes:

struct fitnessTracking {
    char activity[50], unit[50];
    int calories;
    float total, weight, height, bmi;
};
struct recordDate {
    int dd, mm, yyyy;
    int duration;
};
struct user {
    char username[50];
    struct fitnessTracking tracker;
    struct recordDate record;
};

struct Number {
    struct Number *ptrnext;
    struct user member;
};

struct Number *newptr, *currentptr;

Here is my activity sort function:

void activitySort(struct Number *head){
    struct Number *temp = NULL; struct Number *ptr=NULL;
    currentptr = head;

    if(head == NULL)
        return;

    while(currentptr != NULL){ //while current pointer not null
        ptr = currentptr->ptrnext;
        while(ptr != NULL){
            if(currentptr->member.tracker.activity > ptr->member.tracker.activity){
                temp = currentptr->member.tracker.activity;
                currentptr->member.tracker.activity = ptr->member.tracker.activity;
                ptr->member.tracker.activity = temp;
            }ptr = ptr->ptrnext;
        }currentptr=currentptr->ptrnext;
    }
}

The error shows on these 2 lines with the error code error: assignment to expression with array type

currentptr->member.tracker.activity = ptr->member.tracker.activity;
ptr->member.tracker.activity = temp;

How can I fix them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文