Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int string_matching(char *,char *);
  4. int main()
  5. {
  6.     char miotesto[100],miachiave[20];
  7.     int n_occorenze;
  8.     puts("Inserire Testo:");
  9.     gets(miotesto);
  10.     puts("Inserire Chiave:");
  11.     gets(miachiave);
  12.     n_occorenze=string_matching(miachiave,miotesto);
  13.     printf("\nLa stringa '%s' appare %d volte nel testo\n'%s'\n",miachiave,n_occorenze,miotesto);
  14.     return 0;
  15. }
  16. int string_matching(char chiave[],char testo[]){
  17.     int n,m,i,conta_chiave;
  18.     n=strlen(chiave);
  19.     m=strlen(testo);
  20.     conta_chiave=0;
  21.     for(i=0;i<=m-n;i++)
  22.         if(strncmp(chiave,&testo[i],n)==0)
  23.             conta_chiave++;
  24.     return conta_chiave;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement