【C语言】将多个字符串排序输出

#include
#include
#define SIZE 81
#define LIM 20
#define HALT " "
void stsrt(char *strings[], int num);
int main(void)
{
char input[LIM][SIZE];
char *ptstr[LIM];
int ct = 0;
int k = 0;
printf("input up to %d lines, and I will sort them . \n", LIM);
printf("To stop ,press the enter key at a line's start .\n");
while (ct < LIM && gets_s(input[ct], 100) != NULL && input[ct][0] != '\0')
{
ptstr[ct] = input[ct];
ct++;
}
stsrt(ptstr, ct);
puts("\n here's the sorted list:\n");
for (k = 0; k < ct; k++)
{
puts(ptstr[k]);
}
puts("\n here's the list:\n");
for (k = 0; k < ct; k++)
{
puts(input[k]);
}






return 0;
}
void stsrt(char *strings[], int num)
{
char *temp;
int top, seek;
for (top = 0; top < num - 1; top++)
{
for (seek = top + 1; seek < num; seek++)
{




if (strcmp(strings[top], strings[seek])>0)
{
temp = strings[top];
strings[top] = strings[seek];
strings[seek] = temp;


}
}




}



【C语言】将多个字符串排序输出_第1张图片

}



你可能感兴趣的:(每天十道编程题)