70,021
社区成员




#include <stdio.h>
#include <string.h>
#define MAXLINES 5000 /* 待排序的最大行数*/
char *lineptr[MAXLINES]; /* 指向文本行的指针*/
int readlines(char *lintptr[ ], int nlines);
void writelines(char *lineptr[ ], int nlines);
void qsort(void *lineptr[ ], int left, int right,
int (*comp) (void *, void *));
int numcmp(char *, char *);
main(int argc, char *argv[ ])
{
int nlines;
int numeric = 0;
if (argc > 1 && strcmp(argv[1], "-n ") = = 0)
numeric = 1;
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
qsort((void **) lineptr, 0, nlines-1,
(int (*)(void *, void *)) (numeric ? numcmp : strcmp)); //这里不明白!
writelines(lineptr, nlines);
return 0;
}else {
printf("input too big to sort\n");
return 1;
}
}
(int (*)(void *, void *));
typedef int (*ComFuncType)(void *, void *);
qsort((void **) lineptr, 0, nlines-1,
(ComFuncType)(numeric ? numcmp : strcmp));