-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHangman.c
More file actions
88 lines (85 loc) · 1.97 KB
/
Hangman.c
File metadata and controls
88 lines (85 loc) · 1.97 KB
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
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i,j,c,count=0,flag=0,*ptr,counter;
char a[1][1000],pl1[100],pl2[100];
char b[10],alpha;
char d='_';
printf("enter the names of the two players playing\n");
scanf("%s %s",pl1,pl2);
printf("%s to enter his word to be hidden first\n",pl1);
scanf("%s",a);
c=strlen(&a[0][0]);
system("cls");
printf("\n\n\t\t\t ** HANGMAN ** \n");
printf("\n\t\t\t**************\t\t\t");
printf("\n\t\t\t..............\n\n\t\t\t ");
for(j=0;j<c;j++)
{
printf("%c ",d);
b[j]=d;
}
printf("\n\n\t\t\t..............\t\t\t");
printf("\n\n\t\t\t**************");
while (count<6)//||(ans<c))
{
counter=0;
flag=0;
printf("\n\n\n\n\n\n\t enter a char ");
alpha=getche();
for(i=0;i<c;i++)
{
if(alpha==b[i])
flag=2;
}
if(flag==0)
{
for(i=0;i<c;i++)
{
if (alpha==a[0][i])
{
b[i]=a[0][i];
flag=1;
}
}
}
system("cls");
printf("\n\n\t\t\t ** HANGMAN ** \n");
printf("\n\t\t\t**************\t\t\t");
printf("\n\t\t\t..............\n\n\t\t\t ");
for(i=0;i<c;i++)
{
printf("%c ",b[i]);
if(b[i]=='_')
counter++;
}
printf("\n\n\t\t\t..............\t\t\t");
printf("\n\n\t\t\t**************");
if(flag==0)
{
count++;
printf("\n\n\n\n\t\t%c i\as a w\ar\aon\ag guess ",alpha);
printf("\n\n\t\t (You have %d more guesses)",6-count);
}
else if(flag==2)
{
printf("\n\n\t\t\t\tYou have already guessed this earlier.....\n");
printf("\n\t\t\t\tTry again\n");
}
else
{
printf("\n\n\t\t You are correct!!");
printf("\n\t\t(Guess the rest)");
}
if(counter==0 || count==6)
break;
}
if(counter==0)
printf("\n\n\n\t %s won",pl2);
else
printf("\n\n\n\t\t YOU LOSE !!! %s has won.\n\n \t\t **$$ SORRY YOU ARE HANGED $$**",pl1);
getch();
}