Code:
#include<stdio.h>
#define ARRSIZE 50
#define SCREENSIZE 25
int wrongguess=0;
void verify(char arr2[], char arr[], char guess[]);
void low(char arr2[], char arr[]);
void clrscrn(void);
main()
{
char arr[ARRSIZE];
char guess[ARRSIZE];
char arr2[ARRSIZE]={'_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_'};
printf("Enter Phrase:");
fgets(arr, ARRSIZE, stdin);
clrscrn(); /**Generate newlines**/
while(wrongguess<10000000){ /**>>variable value check here, added a huge value so you could see wrongguess jumping up.<<**/
printf("\nIncorrect guesses #%-3d\nPlayer 2 guess:", wrongguess); /**Wrongguess printed here, thanks gemer........../
fgets(guess, ARRSIZE, stdin);
verify(arr2, arr, guess);
printf("\n%s", arr2);
}
return 0;
}
void verify(char to[],char from[], char guess[])
{
int copy, check, j, k;
extern int wrongguess;
low(to, from);
/**This part replaces newline with null**/
for (copy=0; from[copy]!='\0'; ++copy){
if (from[copy]=='\n'){
from[copy]='\0';
to[copy]='\0';
}
if(guess[copy]=='\n'){
guess[copy]='\0';
}
}
for(check=0; check<ARRSIZE; check++){
for(j=check, k=0; guess[k]!='\0'&& from[j]!='\0'; ++j,++k){
/**For loop pattern check here**/
if (from[j]==guess[k]){
/**copy if correct, slight bug with lining
up addresses of from & guess, can't fix without
rearranging guess**/
to[j]=guess[k];
}
/**if not matching, add 1 to wrongguess-broken**/
else if (from[j]!=guess[k]){
++wrongguess;
break;
}
}
/**punctuation copy**/
if(from[check]==' ' || from[check]=='.' || from[check]=='?' || from[check]=='"' || from[check]==','){
to[check]=from[check];
}
}
}
void low(char to[], char from[])
{
int scan;
/**This only works with ascii, but the tolower function
was having some interaction with the verify function, and
not copying capital letters put arbitrarily at the beginning
of words.**/
for (scan=0; scan<ARRSIZE; ++scan){
if (to[scan]>='A' && to[scan]<='Z')
to[scan]+=32;
if (from[scan]>='A' && from[scan]<='Z')
from[scan]+=32;
}
}
void clrscrn(void)
{
/**This might be better off not as a function, but I didn't
want the for loop dirtying up the main function**/
int i;
for (i=0; i<=SCREENSIZE; ++i){
putchar('\n');
}
}