當前位置:成語大全網 - 新華字典 - 從鍵盤輸入10個字符串,按照字典順序將其排序輸出 二維字符數組

從鍵盤輸入10個字符串,按照字典順序將其排序輸出 二維字符數組

//沒用2為字符串,麻煩死。用的結構體

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

typedef struct {

char c[105];

}Line;

Line a[10];

int cmp(const void *x,const void *y)

{

char *m = ((Line*)x)->c;

char *n = ((Line*)y)->c;

return strcmp(m,n);

}

int main()

{

int L,M,i,x,y,ans;

for(i = 0;i < 10;i ++)

scanf("%s",a[i].c);

qsort(a,10,sizeof(a[0]),cmp);

for(i = 0;i < 10;i ++)

printf("%s\n",a[i].c);

return 0;

}