当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言50套程序修改上机题(43)
发布时间:2011/11/1 10:07:00 来源:城市学习网 编辑:ziteng

  43、给定程序MODI1.C中函数fun的功能是: 在字符串的最前端加入n个*号, 形成新串, 并且覆盖原串。

      注意: 字符串的长度最长允许为79。

      请改正函数fun中指定部位的错误, 使它能得出正确的结果。

      注意: 不要改动main函数, 不得增行或删行, 也不得更改程序的结构!

  #include

  #include

  void  fun (  char  s[], int  n )

  {

     char  a[80] , *p;

     int  i;

  /**********found***********/

     s=p;

     for(i=0; i     do

     {  a[i]=*p;

        i++;

     }

  /**********found***********/

     while(*p++)

     a[i]=0;

     strcpy(s,a);

  }

  main()

  {  int  n;        char  s[80];

     printf("\nEnter a string  :  "); gets(s);

     printf("\nThe string \"%s\"\n",s);

     printf("\nEnter n ( number of * )  :  ");  scanf("%d",&n);

     fun(s,n);

     printf("\nThe string after insert : \"%s\" \n" ,s);

  }

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved