字符串排序,请问我这个程序出什么问题了?
//对一组人名进行排序#include<stdio.h>
#include<string.h>
#define SIZE 7
void sort(char *name[],int num);
int main(){
char *name[SIZE];
int i = 0;
printf("please input 8 name:\n");
for(i = 0;i<SIZE;i++){
gets(name[i]);
}
printf("before sorting name:\n");
for(i = 0;i<SIZE;i++){
printf("%s ",name[i]);
}
printf("\n");
printf("after sorting name:\n");
sort(name,SIZE);
for(i = 0;i<SIZE;i++){
printf("%s ",name[i]);
}
printf("\n");
}
void sort(char *name[],int num){
int i,j;
char *temp = NULL;
//进行排序
for(i = 0;i<num - 1;i++){
for(j = 0;j<num - i - 1;j++){
if(strcmp(name[j],name[j+1] ) > 0)
temp = name[j];
name[j] = name[j+1];
name[j+1] = temp;
}
}
}