qsort(bt->rw[t], bt->num[t],
sizeof(TRELLIS_ATOM *),
(int (*)(const void *,const void *))compare_wid);
Run Code Online (Sandbox Code Playgroud)
bt->rw[t]是一个指向struct指针的指针,bt->[num]是一个int,我不明白第四个参数是什么,除了compare_wid是在某处定义的函数,如下所示:
static int compare_wid( TRELLIS_ATOM* a, TRELLIS_ATOM* b )
{
...
return x;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试让程序读取一个文本文件,其中包含"1001姓氏姓氏10 20 30"等信息,学生人数,姓名,姓氏和3年级.这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
int number;
char name[30];
char surname[30];
int midterm1,midterm2,midterm3;
} Student;
int comp(const void * aa, const void * bb)
{
struct Student a = *(struct Student*)aa;
struct Student b = *(struct Student*)bb;
if (a.midterm1==b.midterm1)
return 0;
else if (a.midterm1 < b.midterm1)
return -1;
else
return 1;
} // comp
int main(void)
{
int choice,studentnumber,midterm1,midterm2,midterm3,i,n;
char surname;
FILE *cfPtr;
struct student *name;
name = malloc( 10 * sizeof(Student));
if …Run Code Online (Sandbox Code Playgroud)