对字符串数组进行排序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Nmax 1000
#define Mmax 10000
char buf[Mmax]; int M=0;
int compare(void *i, void *j);
int main(void)
{
int N;
char *a[Nmax];
for(N=0; N<Nmax; N++)
{
a[N]=&buf[M];
if(scanf("%s", a[N])==EOF) break;
M+=strlen(a[N])+1;
}
qsort(a, N, sizeof(a[0]), compare);
for(int i=0; i<N; i++) printf("%s\n", a[i]);
return 0;
}
int compare(void *i, void *j)
{
return (strcmp(*(char **)i, *(char **)j));
}
posted on 2018-03-01 17:04 MACHINE_001 阅读(175) 评论(0) 编辑 收藏 举报