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

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2013年2月26日
 改错题
  下列给定的程序中,函数fun的功能是:依次取出字符串中所以数字字符,形成新的字符串,并取代原字符串。
  请改正函数fun中的错误,使程序能得出正确的结果。
  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
  试题程序:#include <stdio.h>
  #include <conio.h>
  void fun(char *s)
  {
  int i, j;
  /********found********/
  for (i=0, j=0; s[i]!='\0'; i++)
  if (s[j]>='0' && s[i]<='9')
  s[j] = s[i];
  /********found********/
  s[j] = "\0";
  }
  main()
  {
  char item[80];
  printf("\nEnter a string :");
  gets(item);
  printf("\n\nThe string is : %s\n", item);
  fun(item);
  printf("\n\nThe string of changing is : %s\n", item);
  }
  第1处:s[j]=s[i];应改为s[j++]=s[i]
  第2处:s[j]=”/0”;应改为s[j]=’\0’;

相关文章