Click here to Skip to main content
12,951,606 members (64,095 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.
1- Your program must display the following on initialization:
Row of empty dashes
Total Score
Guesses Left
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
Updated 22-May-12 9:18am

1 solution

Rate this: bad
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:,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.
Vickey93 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 22-May-12 14:14pm 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 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 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

Can you do the first instruction without help? I.e. Display a row of dashes?
Vickey93 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 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;
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 23-May-12 1:28am
Thanks. I am getting it and I think I can figure it out now.
OriginalGriff 23-May-12 2:59am
Well done!
Vickey93 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 <conio.h>
#include <stdio.h>
#include <windows.h>
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");
printf("_ _ _ _ _ _\n");
printf("Enter the alphabet(A-Z):");
else if(z=='u')
else if(z=='n')
else if(z=='a')
else if(z=='i')
else if(z=='d')
printf("Wrong guess \n");

return 0;
void gotoxy(int x,int y)
COORD coord;
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
Top Experts
Last 24hrsThis month
OriginalGriff 6,229
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 22 Sep 2013
Copyright © CodeProject, 1999-2017
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