下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数数组中共有M个字符串,且串长小于N。
#define M 5
#define N 20
int fun(char (*ss)[N], int *n) {
int i, k = 0, len = N;
for (i = 0; i < ______; i++) {
len = strlen(ss[i]);
if (i == 0)
*n = len;
if (len ____ * n) {
*n = len;
k = i;
}
}
return (_____);
}
main() {
char ss[M][N] = {"shanghai", "guangzhou", "beijing", "tianjing",
"chongqing"};
int n, k, i;
printf("\nThe originalb stringsare:\n");
for (i = 0; i < M; i++)
puts(ss[i]);
k = fun(ss, &n);
printf("\nThe length of shortest string is: % d\n", n);
printf("\nThe shortest string is: % s\n", ss[k]);
}