#include
#include
void f(char* p)
{
char max , * q;
int i = 0;
max = p[i];
while (p[i] != '\0')
{
if (max < p[i])
{max = p[i]; q = p + 1; }
i++;
}
while (q > p)
{ *q = *(q - 1); q--; }
p[0] = max;
}
int mani()
{
char str[80] = "abcde";
f(str);
puts(str);
printf("\n");
return 0;
}
这段代码有点问题:
#include <stdio.h>
#include <string.h>
void f(char* p)
{
char max, *q;
int i = 0;
max = p[i];
q = p;
while (p[i] != '\0')
{
if (max < p[i])
{
max = p[i];
q = p + i;
}
i++;
}
if (q > p)
{
while (q < p + strlen(p))
{
*(q - 1) = *q;
q++;
}
*(q - 1) = max;
}
}
int main()
{
char str[80] = "abcde";
f(str);
puts(str);
printf("\n");
return 0;
}
我修改了下,你试试