#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
void bj(char *a[5],int n)
{
int i,j,k;
char *t,*p;
for(i=0;i<4;i++)
{
k=i;
for(j=i+1;j<5;j++)
if(strcmp(a[k],a[j])>0)k=j; //strcmp(a+k,a+j)能运行但是结果又不对
if(k!=i)
{
t=a[k];a[k]=a[i];a[i]=t;
}
}
}
int main()
{
char *p[5];
int i;
for(i=0;i<5;i++)
gets(p+i);
bj(p,5);
for(i=0;i<5;i++)
printf("%s\n",p+i);
system("pause");
return 0;
}
输入5个字符串比较代码编写没有错误运行时候就不行了
新手求哪位大佬解释下
|