实验报告
源程序:
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 int cntstring(char *source,char *substr); 5 void main() 6 { 7 char str1[50],str2[20]; //str1 为主字符串,str2 为子字符串 8 cout<<"input source string:"; 9 cin.getline(str1,50); 10 cout<<"input sub string:"; 11 cin.getline(str2,20); 12 cout<<"Occurs:"<<cntstring(str1,str2)<<endl; 13 } 14 int cntstring(char *source,char *substr) 15 { 16 int sum=0; //统计子字符串数量初值为0 17 char *p1=source,*p2=substr; 18 while(*p1 !='