填空题 下列给定程序中,函数fun的功能是:在形参ss所指字符串数组中,将所有串长超过k的字符串中后面的字符删除,只保留前面的k个字符。ss所指字符串数组中共有N个字符串,且串长小于M。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意 :部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <string.h>
#define N 5
#define M 10
/********found********/
void fun(char (*ss) 1,int k)
{int i=0;
/********found********/
while(i< 2){
/********found********/
ss[i][k]= 3;i++;}
}
main()
{char x[N][M]={"Create","Modify","Sort","skip","Delete"};
int i;
printf("/nThe original string/n/n");
for(i=0;i<N;i++)puts(x[i]);
printf("/n");
fun(x,4);
printf("/nThe string after deleted:/n/n");
for(i=0;i<N;i++)puts(x[i]);
printf("/n");
}
【正确答案】
【答案解析】[M] N "/0" [解析] 填空1:根据main函数中函数调用语句,确定函数定义时的形式参数,所以填入[M]。
填空2: while循环语句需要对所有字符串进行操作,因此循环条件是i<N。
填空3:字符串结尾加入字符串结束标识"/0"。