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

  19、给定程序中,函数fun的功能是:将形参s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。

  例如,s所指字符串为:asd123fgh5##43df,

  处理后新字符串为:123543asdfgh##df。

  请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

  注意:源程序存放在考生文件夹下的BLANK1.C中。

  不得增行或删行,也不得更改程序的结构!

  #include  

  #include  

  #include  

  #include  

  char *fun(char  *s)

  { int  i, j, k, n;    char  *p, *t;

    n=strlen(s)+1;

    t=(char*)malloc(n*sizeof(char));

    p=(char*)malloc(n*sizeof(char));

    j=0; k=0;

    for(i=0; i    {  if(isdigit(s[i])) {

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

         p[__1__]=s[i]; j++;}

       else

       {  t[k]=s[i]; k++; }

     }

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

     for(i=0; i<__2__; i++) p[j+i]= t[i];

     p[j+k]=0;

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

     return __3__;

  }

  main()

  { char  s[80];

    printf("Please input: ");  scanf("%s",s);

    printf("\nThe result is: %s\n",fun(s));

  }

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