//冒泡排序。效率可能不是很高
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char arr[200][15];
int hang=0;
void readData(){
FILE *fp;
if((fp=fopen("1.txt","r"))==NULL){
printf("file open error!!\n");
exit(0);
}
while(!feof(fp)){
fscanf(fp,"%s",arr[hang++]);
if(strlen(arr[hang-1])==0)
{
hang--;
break;
}
}
fclose(fp);
}
void writeData(){
FILE *fp;
if((fp=fopen("2.txt","w"))==NULL){
printf("file open error!!\n");
exit(0);
}
int i=0;
while(i<hang){
fprintf(fp,"%s\n",arr[i]);
i++;
}
fclose(fp);
}
void rank(){
char ch[15];
char (*p)[15]=arr;
for(int i=0;i<hang-1;i++){
for(int j=0;j<hang-1-i;j++){
if(strlen(p[j])>strlen(p[j+1])){
strcpy(ch,arr[j]);
strcpy(arr[j],arr[j+1]);
strcpy(arr[j+1],ch);
}
}
}
}
int main()
{
readData();
rank();
writeData();
return 0;
}