作者:不详 来源:互联网   酷勤网收集 2008-04-23

摘要
  统计一个长度为2的子字符串在另一个字符串中出现的次数。例如:假定输入的字符串为asd asasdfg asd as zx67 asd mklo,子字符串为as,函数返回值为6。函数readwriteDat()的功能是实现从文件in.dat中读取两个字符穿4,并调用函数findstr()

    题目19:编写一个函数findstr(),该函数统计一个长度为2的子字符串在另一个字符串中出现的次数。例如:假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为"as",函数返回值为6。
    函数readwriteDat()的功能是实现从文件in.dat中读取两个字符穿4,并调用函数findstr(),最后把结果输出到文件out.dat中。
    注意:部分源程序已给出。
    请勿改动主函数main()和函数ReadWrite()的内容。
-----------------------
int findStr(char *str,char *substr)
  { int  n;
    char  *p , *r;
    n=0;
    while ( *str )
   {  p=str;
      r=substr;
      while(*r)
      if(*r==*p) {  r++;  p++;  }
      else  break;
      if(*r=='\0')
      n++;
      str++;   }
   return  n;
  }

分类: 题库中心 南开100题

上一篇:题目88:以行为单位对字符按从小到大的顺序进行排序   下一篇:题目20:求Fibonacci数列中大于t的最小的一个数