1个回答
展开全部
希望能对你有所启发
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int pattern_match_num(char *text, char *key )
{
int count=0;
char *p;
p = strstr(text, key);
while(p != NULL)
{
count++;
p = strstr(text+(strlen(text)-strlen(p))+strlen(key), key);
}
return count;
}
int main(int argv,int *argc[])
{
char src[]= "I have a pink pen. You have a pencil. He has a coupe ";
char key[]= "pen ";
int result;
result = pattern_match_num(src, key);
printf( "The result is %d.\n ", result);
system( "PAUSE ");
return 0;
}
int pattern_match_num(const char *text, const char *key )
{
int count=0;
const char *p = text;
p = strstr(p, key);
while(p != NULL)
{
if(isalpha(*(p-1))==0&&isalpha(*(p+strlen(key)))==0)
count++;
p = strstr(p+strlen(key), key);
}
return count;
}
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int pattern_match_num(char *text, char *key )
{
int count=0;
char *p;
p = strstr(text, key);
while(p != NULL)
{
count++;
p = strstr(text+(strlen(text)-strlen(p))+strlen(key), key);
}
return count;
}
int main(int argv,int *argc[])
{
char src[]= "I have a pink pen. You have a pencil. He has a coupe ";
char key[]= "pen ";
int result;
result = pattern_match_num(src, key);
printf( "The result is %d.\n ", result);
system( "PAUSE ");
return 0;
}
int pattern_match_num(const char *text, const char *key )
{
int count=0;
const char *p = text;
p = strstr(p, key);
while(p != NULL)
{
if(isalpha(*(p-1))==0&&isalpha(*(p+strlen(key)))==0)
count++;
p = strstr(p+strlen(key), key);
}
return count;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询