如何在分类结构C中使用数组类型误差将分配固定到表达式C
当我尝试比较指向结构的指针时,如何修复“使用数组类型的分配到表达式”。我想通过使用条件要求用户选择他们想根据给定选择对用户数据进行分类,从而根据所选列(例如活动)对用户数据进行排序。然后,我想运行程序,然后出现问题。
这是我的代码结构:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论