填空题 请补充函数proc(),该函数的功能是:依次取出字符串中所有的小写字母以形成新的字符串,并取代原字符串。
例如,若输入:everyONE!,则输出:every。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void proc(char*str)
{
int i=0;
char*p=str;
while( 1)
{
if(*p>="a"&&*p<="z")
{
str[i]=*p;
2;
}
p++;
}
str[i]= 3;
}
void main()
{
char str[80];
system("CLS");
printf("/nEnter a string: ");
gets(str);
printf("/n/nThe string is: %s/n", str);
proc(str);
printf("/n/nThe string of changing is: %s/n", str);
}
【正确答案】
【答案解析】*p i++ "/0"[解析] 由函数proc()可知,指针变量p是指向字符串str的指针,用来判断字符串是否结束,因此,第一处填“*p”;变量i为新字符串数组的下标,每检查到一个符合要求的字符,数组下标加1,因此,第二处填“i++”;最后,要为新的字符串数组添加结束符,因此,第三处填“"/0"”。