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

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2013年4月25日
 编程题
  请编写fun函数,函数的功能是:从字符串中删除指定的字符,同一字母的大,小写按不同的字母处置,
  例如:若程序执行时输入字符串为:turbo c and borland c++
  从键盘上输入字符n,则输出后变为:turbo c ad borlad c++
  如果输入 的字符在字符串中不存在,则照原样输出
  注意:部分源程序给出如下。
  请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
  试题程序:
  #include
  #include
  void fun(char s[],int c)
  {
  }
  main()
  {
  static char str[]="turbo c and borland c++";
  char ch;
  FILE *out; 
  printf("??ê?×???′?:%s\n",str);
  printf("ê?è?ò???×???:");
  scanf("%c",&ch);
  fun(str,ch);
  printf("str[]=%s\n",str);
  strcpy(str, "turbo c and borland c++");
  fun(str, 'a');
  out = fopen("out.dat", "w");
  fprintf(out, "%s", str);
  fclose(out);
  }
  答案是:
  void fun(char s[],int c)
  {
  int i=0;
  char *p;
  p=s;
  while(*p)
  {
  if(*p!=c)
  {
  s[i]=*p;
  i++;
  }
  p++;
  }
  s[i]=’\0’;
  }
首页 1 2 3 尾页

相关文章