按照从小到大的输出几组字符串,但是结果并不是从小到大,为什么
#include"stdio.h"//输出异常。#include "string.h"
void main()
{
void sort(char*name[],int n);
void print(char*name[],int n);
char*name[]={"Follow me","BASIC","Great Wall","FORTRAN","Computer design"};
int n=5;
sort(name,n);
print(name,n);
}
void sort(char *name[],int n)
{
char *temp;
int i,j,k;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(strcmp(name[k],name[j])>0)k=j;
if(k!=i)
{
temp=name[k];
name[k]=name[j];
name[j]=temp;
}
}
}
}
void print(char*name[],int n)
{
for(int i=0;i<n;i++)
{
printf("%s\n",name[i]);
}
return:
Follow me
Great Wall
Fortran
Computer design
BASIC