填空题
请补充函数proc(),该函数的功能是:把字符串str中的字符按字符的ASCII码降序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。
例如,如果输入“abcdefg”,则输出为“gfedcba”。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define N 80
void proc(char str[],int n)
{
int i,j;
char ch;
for(i=0;i<n;i++)
for(j=
1;j<n;j++)
if(str[i]<str[j])
{
ch=str[j];
2;
str[i]=ch;
}
}
void main()
{
int i=0,strlen=0;
char str[N];
system("CLS");
printf("/nInput a string:/n");
gets(str);
while(str[i]!="/0")
{
strlen++;
i++;
}
proc(str,strlen);
printf("/n***display string***/n");
puts(str);
}