现在的位置: 首页 > 综合 > 正文

母字符串中统计子字符串的个数

2012年05月24日 ⁄ 综合 ⁄ 共 358字 ⁄ 字号 评论关闭

 

#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
  int i,j=0,k,count;
  char s1[100],s2[100];
  printf("Enter main String:");
  gets(s1);
  printf("Enter Sub String:");
  gets(s2);
  count=0;
/**/ for(i=0;s1[i]!='\0';i++) /**/
 {

/**/ for(k=0,j=i; (s1[j]==s2[k])&&(s1[j]!='\0'); j++,k++ ); /**/
  if(s2[k]=='\0') count++;
  }
  printf("\nCount=%d\n",count);
 // getch();
 // return 0;
}

抱歉!评论已关闭.