当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言50套程序编写上机题及答案(35)
发布时间:2011/10/31 17:49:42 来源:城市学习网 编辑:ziteng

  35、编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为: asd asasdfg asd as zx67 asd mklo,子字符串为:as,则应输出6。

      注意:部分源程序在文件PROG1.C中。

      请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

  #include

  #include

  int fun(char *str,char *substr)

  {

  }

  main()

  {

    void

    char str[81],substr[3];

    int n;

    printf("输入主字符串: ");

    gets(str);

    printf("输入子字符串: ");

    gets(substr);

    puts(str);

    puts(substr);

    n=fun(str,substr);

    printf("n=%d\n",n);

  }

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