[英]C - "error in working with structure pointers"
我有一個 function,我向其發送數組結構的元素,但由於某種原因,錯誤不斷出現
typedef struct student{
char *fullName;
char groupNumber[8];
float GPA;
}student;
int cmpName(student* p1, student* p2){
printf("%s\n",p1->fullName);
return (strcmp(p1->fullName,p2->fullName));
}
void gnomeSort(student **mass,int size,int (*cmpFunc)(student *p1, student *p2)){
int index = 0;
while (index < size){
if (index == 0)
index++;
if (cmpFunc(mass[index],mass[index-1]))
index++;
else{
student *tmp;
tmp = mass[index-1];
mass[index-1] = mass[index];
mass[index] = tmp;
index--;
}
}
}
我知道問題很可能在指針中,但我不知道如何解決
盡量不要在 arguments 中制作 function
void gnomeSort(student **mass,int size,int (*cmpFunc)(student *p1, student *p2))
將int (*cmpFunc)(student *p1, student *p2)
替換為int param
並獨立執行 function cmpName()
,然后調用gnomeSort()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.