當前位置:編程學習大全網 - 網站源碼 - 計算字符串中子串出現的次數.要求:用壹個子函數subString()實現,參數為指向該字符串和要查找的子串的指針

計算字符串中子串出現的次數.要求:用壹個子函數subString()實現,參數為指向該字符串和要查找的子串的指針

//#include "stdafx.h"//vc++6.0加上這壹行.

#include "stdio.h"

#include "string.h"

int subString(const char *p,const char *psub){

int n;

char *ptmp;

for(n=0;*p;p++)

if(ptmp=strstr(p,psub)){

n++;

p=ptmp;

}

return n;

}

void main(void){

char a[200],b[100];

printf("Enter a string(ln<200)...\nstr1=");

gets(a);

printf("Type a subString(ln<100)...\nstr2=");

gets(b);

printf("There is(are) %d.\n",subString(a,b));

}

  • 上一篇:醫藥進銷存管理系統無法連接數據庫
  • 下一篇:在AL釣魚遇到“魚竿發出奇異的亮光”時該怎麽釣?
  • copyright 2024編程學習大全網