Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int string_matching(char *,char *);
- int main()
- {
- char miotesto[100],miachiave[20];
- int n_occorenze;
- puts("Inserire Testo:");
- gets(miotesto);
- puts("Inserire Chiave:");
- gets(miachiave);
- n_occorenze=string_matching(miachiave,miotesto);
- printf("\nLa stringa '%s' appare %d volte nel testo\n'%s'\n",miachiave,n_occorenze,miotesto);
- return 0;
- }
- int string_matching(char chiave[],char testo[]){
- int n,m,i,conta_chiave;
- n=strlen(chiave);
- m=strlen(testo);
- conta_chiave=0;
- for(i=0;i<=m-n;i++)
- if(strncmp(chiave,&testo[i],n)==0)
- conta_chiave++;
- return conta_chiave;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement