填空题
下列给定程序中,函数fun的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码值升序排序后输出。例如,若输入"edcba",则应输出"abcde"。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<string.h>
#include<stdio.h>
void fun(char t[])
{
char c;
int i,j;
/*********found*********/
for(i=strlen(t);i;i--)
for(j=0;j<i;j++)
/*********found*********/
if(t[j]<t[j+1])
{
c=t[j];
t[j]=t[j+1];
t[j+1]=c;
}
}
main()
{
char s[81];
printf("/nPlease enter a character string:");
gets(s);
printf("/n/nBefore sorting:/n%s",s);
fun(s);
printf("/nAfter sorting decendingly:/n%s",s);
}