69,373
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int my_cmp(const void *a, const void *b)
{
char *p = *(char **)a;
char *q = *(char **)b;
return strcmp(p, q);
}
int main(void)
{
char word[21], *arr[10];
int i, size = 0;
while(1)
{
scanf("%s", word);
if(strcmp(word, "END") == 0) break;
arr[size] = malloc(strlen(word) + 1);
strcpy(arr[size], word);
size++;
if(size == 10) break;
}
qsort(arr, size, sizeof(char *), my_cmp);
for(i=0; i<size; i++)
{
printf("%s\t", arr[i]);
free(arr[i]);
}
return 0;
}
#define MAX_COL_SIZE 21
int input(char ar2[][MAX_COL_SIZE])
{
int i=0;
//while(i<10&&ar2!='*END*')
while(i<10&&strcmp(ar2[i], "END"))
{
//gets(ar2);
fgets(ar2[i], MAX_COL_SIZE, stdin);
i++;
}
return i;
}