求字符串中的某个子串重复次数
#include<stdio.h> int count_substr(char *str, char *substr) { int count = 0; char *p = substr; while(*str != '\0') { while( *p != '\0') { if( *(str++) != *(p++) ) { if( *(str-1) == substr[0] && *str == substr[1]) str = str - 1; break; } if ( *p == '\0') count = count + 1; } p = substr; } return count; } int main() { char *str = "wdxdsdfasdfxwdddxddwddxwdxxxx"; char *substr = "wdx"; int i = count_substr(str, substr); printf("%d\n",i); }
作者:小德cyj
出处:http://www.cnblogs.com/dongzhuangdian
欢迎转载,希望注明出处