填空题
给定程序中,函数fun的功能是:对形参ss所指字符串数组中的M个字符串按长度由短到长进行排序。ss所指字符串数组中共有M个字符串,且串长<N。
请在程序的下划线处填入正确的内容,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include <stdio.h>
#include <string.h>
#define M 5
#define N 20
void fun(char (*ss)[N])
{ int i,j,k,n[M]; char t[N];
for(i=0; i<M; i++) n[i]=strlen(ss[i]);
for(i=0; i<M-1; i++)
{ k=i;
/**********found**********/
for(j=______;j<M;j++)
/**********found**********/
if(n[k]>n[j])______;
if(k!=i)
{ strcpy(t,ss[i]);
strcpy(ss[i],ss[k]);
/**********found**********/
strcpy(ss[k],______);
n[k]=n[i];
}
}
}
main()
{ char ss[M][N]={'shanghai','guangzhou','beijin g','tianjing','cchongqing'};
int i;
printf('\nThe original strings are:\n');
for(i=0; i<M;i++)printf('%s\n',ss[i]);
printf('\n');
fun(ss);
printf('\nThe result:\n');
for(i=0; i<M; i++) printf('%s\n',ss[i]);
}