下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。 例如,给字符串s输入:AAaaBBbb123 CCcccd,则应输出: upper=6,lower=8。请改正程序中的错误,使它得出正确的结果。 注意:

admin2017-09-23  20

问题 下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。
    例如,给字符串s输入:AAaaBBbb123 CCcccd,则应输出:
    upper=6,lower=8。请改正程序中的错误,使它得出正确的结果。
    注意:部分源程序在文件MODI1.C中,不要改动main函数,不得增行或删行,也不得更改程序的结构!
  试题程序:
#include  < stdio.h >
/*********found*********/
void fun ( char *s, int a, int b )
{
whiie (*s )
if(*s >=’A’&&* s  < =’Z’)
/*********found*********/
    *a=a+1;
if(*s >=’a’&& S < =’z’)
/*********found*********/
        s ++ ;
    }
}
main ( )
{ char s[100]; int upper = 0,
lower = 0 ;
   printf ( "\nPlease a string : " ) ;
gets ( s );
  fun ( s, & upper, &lower );
  printf ( " \ n uppelr =% d lower
=%d\n", upper, lower ) ;
}

选项

答案(1)void fun(char *s,int *a,int *b) (2)*a=*a+1; (3)*b=*b+1;

解析 (1)由主函数中调用fun函数的语句fun(s, &upper,&lower)可知,函数的后两个变量为指针的形式,所以用*a和*b。
(2)*a的作用是用来记录大写字母的个数,此处的作用是对*a累加1,所以此处应改为*a=*a+1。
(3)*b的作用是用来记录小写字母的个数,此处的作用是对*b累加1,所以此处应改为*b=*b+1。
转载请注明原文地址:https://kaotiyun.com/show/Wzxp777K
0

最新回复(0)