Exemple #1
0
void bollywood_game(char text[100])
{
    int n,shadow[100],i,chance,win,m,result,temp;
    char pattern[100],name[50]="BOLLYWOOD";
    n=strlen(text);
    temp='a'-'A';
    for(i=0;i<n;i++)
        if(text[i]>='A' && text[i]<='Z')
            text[i]+=temp;
    for(i=0;i<n;i++)
    {
        if(text[i]==' ')
            shadow[i]=1;
        else
            shadow[i]=0;
    }
    for(chance=9,win=0;chance>0 && win==0;)
    {
        printf("Number of chances left : ");
        for(i=9-chance;i<9;i++)
            printf("%c ",name[i]);
        printf("\n\n\tMovie name is : \n\n\t\t");
        for(i=0;i<n;i++)
        {
            if(shadow[i]==1)
                printf("%c",text[i]);
            else
                printf("%c",'_');
            printf(" ");
        }
        printf("\n\nEnetr the letter : ");
        gets(pattern);
        m=strlen(pattern);
        for(i=0;i<m;i++)
            if(pattern[i]>='A' && pattern[i]<='Z')
                pattern[i]+=temp;
        shift_table(pattern,m);
        result=horspool(text,pattern,shadow);
        if(result==-1)
        {
            printf("Letter not found!\n");
            chance--;
        }
        else
            for(i=0,win=1;i<n;i++)
                if(shadow[i]==0)
                    win=0;
    }
    if(win==1)
        printf("Correct movie! You have won the game! \n\n\tMovie name : %s",text);
    else
        printf("You have run out of chances! Sorry you lose the game...\n\tMovie name : %s",text);
}
main()
{
	char scr[100],pat[100];
	int pos;
	printf("Enter the text : ");
	scanf("%[^\n]",scr);
	printf("Enter the pattern : ");
	scanf("%s",pat);

	shift(pat);
	pos=horspool(scr,pat);
	if(pos>=0)
		printf("\nThe pattern found at position %d\n",pos+1);
	else 
		printf("\nPattern not found\n");
	return 0;
}