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); }
void test_shift_table() { int n = 4; int *f = (int*)malloc(n*sizeof(int)); int *tmp = (int*)malloc(n*sizeof(int)); f[0] = 3; f[1] = 5; f[2] = 2; f[3] = 7; printf("F:\n%d | %d\n%d | %d\n", f[0], f[1], f[2], f[3]); shift_table(f, tmp, n); printf("F SHOULD BE:\n2 | 3\n7 | 5\n"); printf("F IS:\n%d | %d\n%d | %d\n", f[0], f[1], f[2], f[3]); free(f); free(tmp); }