用C语言编写一个程序要求输入的字符串按由大到小输出

来源:百度知道 编辑:UC知道 时间:2024/05/21 17:09:38

#include <conio.h>
#include <stdio.h>
#define MAXLINE 20
void fun(char *pstr[6])
{
int i, j;
char *p;
for(i=0;i<5;i++)
for(j=i+1;j<6;j++)
/*******************found*****************/
if(strcmp(*(pstr+i),*(pstr+j))<0)
{
p=*(pstr+i);
*(pstr+i)=*(pstr+j);
/*******************found*****************/
*(pstr+j)=p;
}
}
main()
{
int i;
char *pstr[6],str[6][MAXLINE];
clrscr();
for(i=0;i<6;i++)
pstr[i]=str[i];
printf("\nEnter 6 string(1 string at each line):\n");
for(i=0;i<6;i++)
scanf("%s",pstr[i]);
fun(pstr);
printf("The strings after sorting:\n ");
for(i=0;i<6;i++)
printf("%s\n ",pstr