2013年计算机二级C语言上机题库三十一_第2页

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2013年5月13日
 改错题
  下列给定程序中,函数fun的功能是:将字符串tt中的小写字母都改成对应的大写字母,其他字符不变,例如输入Ab,cD,则输出AB,CD。
  请改正程序中的错误,使其能得出正确结果。
  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
  试题 程序:
  #include <conio.h>
  #include <stdio.h>
  #include <string.h>
  char *fun(char tt[])
  {
  int i;
  /********found********/
  for (i=0; tt[i]; i++)
  if ((tt[i] >= 'a') || (tt[i]<='z'))
  /********found********/
  tt[i] += 32;
  return (tt);
  }
  main()
  {
  char tt[81];
  printf("\nPlease enter a string:");
  gets(tt);
  printf("\nThe result string is :\n%s", fun(tt));
  }
  第1处:if ((tt[i]>=’a’)||(tt[i]<=’z’))应改为if ((tt[i]>=’a’)&&(tt[i]<=’z’))
  第2处:tt[i]+=32;应改为tt[i]-=32;

相关文章