📄 qsort_small.c
字号:
#include <stdlib.h>#include <stdio.h>#include <string.h>#define UNLIMIT#define MAXARRAY 60000 /* this number, if too large, will cause a seg. fault!! */struct myStringStruct { char qstring[128];};int compare(const void *elem1, const void *elem2){ int result; result = strcmp((*((struct myStringStruct *)elem1)).qstring, (*((struct myStringStruct *)elem2)).qstring); return (result < 0) ? 1 : ((result == 0) ? 0 : -1);}intmain(int argc, char *argv[]) { struct myStringStruct array[MAXARRAY]; FILE *fp; int i,count=0; if (argc<2) { fprintf(stderr,"Usage: qsort_small <file>\n"); exit(-1); } else { fp = fopen(argv[1],"r"); while((fscanf(fp, "%s", &array[count].qstring) == 1) && (count < MAXARRAY)) { count++; } } printf("\nSorting %d elements.\n\n",count); qsort(array,count,sizeof(struct myStringStruct),compare); for(i=0;i<count;i++) printf("%s\n", array[i].qstring); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -