-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhashup.C
More file actions
80 lines (78 loc) · 1.2 KB
/
Copy pathhashup.C
File metadata and controls
80 lines (78 loc) · 1.2 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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char *a,q[100],*ptr;
int i=0,tr=5;
void getquestion()
{
printf("enter the question.\n");
scanf("%[^\n]s",q);
}
void replacement()
{
do
{
if(q[i]!=' ')
a[i]='_';
else
a[i]=' ';
i++;
}while(q[i]!='\0');
a[i]='\0';
}
void guess()
{
int j=0,k=1,hash[26];
i=0;
while(1)
{
printf("\n%s\n",a);
printf("\nmake your guess by typing the letter\n");
fflush(stdin);
scanf("%c",ptr);
if(hash[*ptr-97]==1)
printf("u have already made the same guess");
else
{
for(j=0;a[j]!='\0';j++)
{
if(*ptr==q[j])
{
a[j]=q[j];
k=2;
}
}
if(k==1)
{
if(tr>1)
printf("wrong guess. you can make only %d more wrong guesses. Beware! ur man at stake",--tr);
else
tr--;
}
k=1;j=0;
for(j=0;a[j]!='\0'&&a[j]!='_';j++);
if(a[j]=='\0')
{
printf("\n%s",a);
printf("U have saved ur man ");
break;
}
if(tr==0)
{
printf("u lost");
break;
}
hash[*ptr-97]=1;
}
i++;
}
}
int main()
{
ptr=(char*)malloc(sizeof(char));
getquestion();
a=(char*)malloc((strlen(q)+1)*sizeof(char));
replacement();
guess();
return 0;
}