Here you will get complete source code guessing a character in a secret sentence or word in C Programming language. you can set your secret message or sentence in the code and then you can tell your friend to start guessing that secret message after executing the code.
One of my Facebook Page’s fan Faster Msr posted this on my page, so I coded to implement this using C Programming language.


Source Code of Program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
/* Author - Nisar Ahmed. Date - 28 June 2015. */ #include < conio.h> #include < stdio.h> #include < string.h> int main(){ int i,totalTry=0,totalChar = 0, charCorrect = 0, charIncorrect = 0, score = 0; char displayMsg[80], orgMsglwr[80]; char orgMsg[] = "C programming"; char ch,temp; for(i=0;i< strlen(orgMsg);i++){ orgMsglwr[i] = orgMsg[i] >= 97 ? orgMsg[i]-32 : orgMsg[i]; if(orgMsg[i] == ' ') displayMsg[i] = ' '; else{ displayMsg[i] = '*'; totalChar++; } } displayMsg[i] = '\0'; orgMsglwr[i]='\0'; totalTry = totalChar; // Set accordingly textbackground(WHITE); textcolor(BLUE); while(charIncorrect < totalTry){ clrscr(); textcolor(RED); gotoxy(30,3); cprintf("799 Web Nixar's Coding"); gotoxy(20,5); cprintf("The program finds character in sentence"); gotoxy(10,7); cprintf("If any character is already found then it is disabled."); textcolor(YELLOW); gotoxy(25,9); cprintf("%s",displayMsg); gotoxy(10,11); textcolor(BLACK); cprintf("Please find character : "); ch = getch(); cprintf("%c",ch); temp = ch >= 97 ? ch-32 : ch+32; if(ch == ' '|| ch =='\r' || strchr(displayMsg,ch) != NULL || strchr(displayMsg,temp) != NULL) continue; ch = ch>=97 ? ch-32 : ch; if(NULL == strchr(displayMsg,ch) && NULL != strchr(orgMsglwr,ch)){ charCorrect++; score++; for(i=0;i< strlen(orgMsg);i++){ // Below two lines convert the character to lowercase temp = orgMsg[i] >= 97 ? orgMsg[i]-32 : orgMsg[i]; ch = ch >=97 ? ch-32 : ch; if(temp == ch){ displayMsg[i] = orgMsg[i]; } } }else{ charIncorrect++; } gotoxy(10,15); cprintf("Message : "); textcolor(YELLOW); cprintf(displayMsg); textcolor(BLACK); gotoxy(10,17); cprintf("Character correct : %d",charCorrect); gotoxy(40,17); cprintf("Character incorrect : %d",charIncorrect); gotoxy(10,19); cprintf("Score : %d",score); gotoxy(10,21); if(NULL == strchr(displayMsg,'*')) break; if(charIncorrect != totalTry) cprintf("Press any key to continue..."); else cprintf("Game Over!!!"); getch(); } if(totalTry != charIncorrect) cprintf("Hurray! You Won"); getch(); return 0; } |