请编写函数fun,对长度位7个字符的字符串,除首尾字符外,将其余5个字符按ASCII码降序排列
#include <stdio.h>
#include <string.h>
void sortDescending(char str[])
{
int len = strlen(str);
if (len != 7)
{
printf("字符串长度不为7,无法进行排序。\n");
return;
}
for (int i = 1; i < len - 1; i++)
{
for (int j = 1; j < len - i - 1; j++)
{
if (str[j] < str[j + 1])
{
char temp = str[j];
str[j] = str[j + 1];
str[j + 1] = temp;
}
}
}
}
int main()
{
char str[] = "abcdefg";
printf("原始字符串: %s\n", str);
sortDescending(str);
printf("处理后的字符串: %s\n", str);
return 0;
}
标签:int,降序,len,char,字符串,str,fun,个字符
From: https://www.cnblogs.com/yesiming/p/18255446