Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C GimmeCode
Please some one give the code of simple hangman game in C.
The exact question is:
Write the source code in C to implement “Hangman” game.
Instructions
1- Your program must display the following on initialization:
Row of empty dashes
Total Score
Guesses Left
Guesses
2- The user has to guess a word. He will enter one alphabet at a time.
3- Each input (alphabet) must be compared with the word and the correct guess must be displayed on the screen in place of the dash.
4- Each wrong guess must also be displayed separately for record.
5- To guess the word, user will be given 5 chances. If he enters 5 wrong alphabets, the game should show the “Game over screen” and his “total score”.
6- For each correct guess user must be awarded 10 points.
7- On successful guess of word, the user must be shown the next word to guess.
8- Your program must randomly select a word from a list of hard-coded words.
9- Graphics are not required. However there will be marks for logic and elegant code.
Posted 22-May-12 7:55am
Edited 22-May-12 9:18am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
 
A very quick search using your subject as the search term gave over one million hits: https://www.google.co.uk/search?sugexp=chrome,mod=16&sourceid=chrome&ie=UTF-8&q=Hangman+game+in+C[^]
 
The top hit is the full source code.
So is the second, and the third, and the fourth, and the fifth, and...
 
In future, please try to do at least basic research yourself, and not waste your time or ours.
  Permalink  
Comments
Vickey93 at 22-May-12 14:08pm
   
I have searched a lot....... but due to limited time I am unable to find a good code and what I have found, I am unable to understand it. Actually I am a beginner and have zero experience of programming. So please help me
OriginalGriff at 22-May-12 14:14pm
   
So...you have a lot of code examples of exactly what you are looking for, and you don't understand it.
So rather than looking at it in detail and trying to work out how it works, you want more code.
 
That you probably won't understand either.
 

Were you planning on making coding a career?
Vickey93 at 22-May-12 14:30pm
   
Its a project given by my teacher and it is to be submitted by this Thursday. Actually I am doing Civil Engineering and have Computer programming as minor. What I want is exact code of question. I ain't gonna use programming in my life.
My whole class is suffering due to this project. We have finals starting by this coming Monday. As I mentioned earlier I am just a beginner so I can't understand that what exactly the codes do. I will be really grateful if you help me with this code. Truly saying its for the first time I have ever asked for some help on internet.
OriginalGriff at 22-May-12 14:42pm
   
Ok - the principles are the same in coding as they are in any other branch of engineering:
If you can't do the whole task, break it into smaller tasks and try to do them in sequence.
Your tutors instruction have (pretty much) done that already, so do the first bit:
1) - initilization.
So, set up a basic C program, and create a function called "Init"
Make it do the tasks described, and pick a word. If you can't work out how to do all of them, repeat the process of breaking it into simpler tasks, until you get tasks you can do.
 
For example:
"1- Your program must display the following on initialization:
Row of empty dashes
Total Score
Guesses Left
Guesses"
 
Can you do the first instruction without help? I.e. Display a row of dashes?
Vickey93 at 22-May-12 14:57pm
   
Ya, I can do it. Please have a look at my code but there are large number of problems. Truly saying I had two or more weeks I could have done it. My teacher says the same thing what you just asked me to do. I have discussed it with many of my friends but it seems that none of us can do it without the help of a programming expert. I have wasted a lot of my precious time on this project but what I think is that I can't do it in just one day. I have 5 other subjects to handle. Please have a look at my code and tell me how can I randomly select words and use them in the game. Its the main problem. Please treat me as a new in programming. I can't understand much.
OriginalGriff at 22-May-12 15:46pm
   
How do you set up an array of words? You know this - it's in your course notes!
 
#define MAX_WORD_LENGTH 20
char[][MAX_WORD_LENGTH] words = {"banana", "orange", "trifle", "marmoset"};
char* word;
 
How do you pick a random integer? You know this as well.
 
int index = 0;
...
randomize();
...
index = random(4);
 
Combine the two, and you have a method of selecting a random word. Just pick a random number that is between zero and the number of words minus one, and use that as the index into the array of words.
 
word = words[index];
 
See what I mean? None of this is difficult. None of it is time consuming. All it takes is you to do what your tutor is trying to teach you to do: to think about problems and work out solutions. Even for a beginner (and you aren't a complete beginner, your code shows that) this is a pretty simple task: a couple of hours to design, implement and test.
So stop procrastinating, stop going "I can't do it, I can't do it", pull your thumb out of your ass, and do it!
Vickey93 at 23-May-12 1:28am
   
Thanks. I am getting it and I think I can figure it out now.
OriginalGriff at 23-May-12 2:59am
   
Good!
Well done!
Vickey93 at 22-May-12 14:35pm
   
I have wasted about 2 days in just searching and understanding the code and what I have done yet is: and I understand it. I was trying to understand the basic skeleton so i did it but I can't do anymore.
#include
#include
#include
void gotoxy(int x,int y);
int main(int argc,char *argv[])
{
char a[6]={'j','u','n','a','i','d'};
char z=0;
printf("Wecome to the hangman game\n");
printf("You have to guess the word shown \n\n You have 5 chances to guess otherwise the game will be over \n\n Each successful guess wil give you 10 points");
printf("\n Score");
printf("\nThe Game starts now.Guess the given word \n");
gotoxy(7,7);
printf("_ _ _ _ _ _\n");
do
{
printf("Enter the alphabet(A-Z):");
scanf_s("%char",&z);
if(z=='j')
{
gotoxy(7,7);
printf("%c",z);
printf("\n\n");
}
else if(z=='u')
{
gotoxy(9,7);
printf("%c",z);
printf("\n\n");
}
else if(z=='n')
{
gotoxy(11,7);
printf("%c",z);
printf("\n\n");
}
else if(z=='a')
{
gotoxy(13,7);
printf("%c",z);
printf("\n\n");
}
else if(z=='i')
{
gotoxy(15,7);
printf("%c",z);
printf("\n\n");
}
else if(z=='d')
{
gotoxy(17,7);
printf("%c",z);
printf("\n\n");
}
else{
printf("Wrong guess \n");
z++;

}
}while(z!=5);
_getch();
return 0;
}
void gotoxy(int x,int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Nirav Prabtani 298
1 OriginalGriff 289
2 Sergey Alexandrovich Kryukov 225
3 _Amy 165
4 Richard MacCutchan 135
0 OriginalGriff 7,799
1 Sergey Alexandrovich Kryukov 6,966
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 22 Sep 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100