题目: 下列给定程序中,函数fun的功能是:在字符串str中找出ASCII码值最大的字符,将其放在第一个位置上;并将该字符前的原字符向后顺序移动。例如,调用fun函数之前给字符串输入:ABCDeFGH,调用后字符串中的内容为eABCDFGH。
#include <stdio.h>
/********found********/
fun(char *p)
{
char max,*q; int i=0;
max=p[i];
while(p[i]!='\0')
{
if(max<=p[i])
{
/********found********/
max=p[i];
q=p+i;
}
i++;
}
while(q>p)
{
*q=*(q-1);
q--;
}
p[0]=max;
}
main()
{
char str[80];
printf("Enter a string: ");
gets(str);
printf("\nThe original string: ");
puts(str);
fun(str);
printf("\nThe string after moving: ");
puts(str);
printf("\n\n");
}