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

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2013年5月13日
  改错题
  下列给定程序中,函数fun的功能是:将s所指字符串中的字母转换为按字母序列的后续字(但Z转换为A,z转换为a),其他字符不变。
  请改正程序中的错误,使其能得出正确结果。
  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
  试题 程序:
  #include <stdio.h>
  #include <ctype.h>
  #include <conio.h>
  void fun(char *s)
  {
  /********found********/
  while (*s != '@')
  {
  if (*s>='A'&&*s<='Z' || *s>='a'&&*s<='z')
  {
  if (*s == 'Z')
  *s = 'A';
  else if(*s == 'z')
  *s = 'a';
  else
  *s += 1;
  }
  /********found********/
  (*s)++;
  }
  }
  main()
  {
  char s[80];
  printf("\n Enter a string with length<80. :\n\n ");
  gets(s);
  printf("\n The string: \n\n ");
  puts(s);
  fun(s);
  printf("\n\n The Cords:\n\n ");
  puts(s);
  }
  第1处:while(*s !=’@’)应改为while(*s)或while(*s!=’\0’)或while(&s!=0)
  第2处:(*s)++;应改为s++;

相关文章