Hangman C source code
By ready2earn
@ready2earn (435)
Italy
December 22, 2006 3:40am CST
Hangman game source code for you.
============
----HANGMAN----
============
Code: C
char word[30],getit[30],*found;
int score,loop,len,num,lup,om,luptimes,times,fitimes,o ndtimes,antimes;
luptimes=0;
fitimes=0;
ondtimes=0;
clrscr();
printf("\n ENTER THE WORD: ");
gets(word);
score=0;
num=0;
om=0;
len=strlen(word);
clrscr();
char gname[70];
printf("\n ENTER YOUR NAME: ");
scanf("%s",gname);
char h;
printf("\n LET's START: ");
h='_';
printf("\n LOOK HERE: ");
for(loop=0;loop!=len;loop++)
{
printf("\n %c ",h);
}
for(loop=0;loop!=len;loop++)
{
om=1;
num=num+1;
fitimes=0;
ondtimes=0;
printf("\n\n %d LETTER",num);
scanf("%s",&getit[num]);
found=strchr(word,getit[num]);
if(found)
{
for(luptimes=0;antimes=1;luptimes!=len;luptimes++, antimes++)
{
if(getit[num]==word[luptimes])
{
fitimes++;
}
else
{
fitimes=fitimes;
}
}
for(luptimes=num;luptimes!=0;luptimes--)
{
if(getit[num]==getit[luptimes])
{
ondtimes++;
}
else
{
ondtimes=ondtimes;
}
}
if(fitimes=ondtimes)
{
score=score+1;
printf("\n OK\n");
for(lup=0;getit[num]!=word[lup];lup++)
{
om++;
}
printf("\n POSITION: %d\n",om);
printf("\n ===================\n");
}
else
{
score=score;
printf("\n NOT AGAIN!\n");
}
}
else
{
score=score;
printf("\n NO\n");
}
}
printf("\n THE WORD IS '%s'\n"word);
printf("\n YOUR SCORE IS %d OUT OF %d",score,len);
getch();
return 0;
}
1 person likes this
8 responses
@dholey (1383)
• India
22 Dec 06
thanks for share, your code is having some errors , it has to be removed first, as it is for c (as you said, variables are to be declared just after the opening of the block, i.e just afer {,string.h must be included befor program, few variables are declared in c++ manner, in the printf () statement (just after the end of for loop "," is missing before word ) ) REST OF THE THINGS ARE SUPERB AND THANKS A LOT FOR THIS ALGORITHM ,
i have mentioned these thing just because if some neo programer wants to run this code he can correct it.....
thanks again....
@ready2earn (435)
• Italy
24 Dec 06
I'm sorry but I was workin on it many month ago but then I quitted my project lol
What do you need exactly?
@shyam4uall (1002)
• India
22 Dec 06
superb..thanks for sharing this code with all of us.But it would have been a great job if you have given it in its corrected form and with whole packed..means ready to use source ..so that like me a begineer can just execute it through any compiler and have the fun..