Note that there are some explanatory texts on larger screens.

plurals
  1. POhangman console game in c
    primarykey
    data
    text
    <pre><code>#include&lt;stdio.h&gt; #include&lt;string.h&gt; #include&lt;time.h&gt; #include&lt;stdlib.h&gt; typedef struct dic { int index; char string[10]; struct dic *next; }node; main() { FILE *fp;int indexrand;node *head;node *mainhead; char s[10],question[10],answer[10];char check; int count=-1,i,j,k,len,flag;head=(node *) malloc(sizeof(node)); mainhead=head; fp=fopen("dictionary.txt","r"); while((fgets(s,10,fp))!=NULL) { strcpy(head-&gt;string,s); count++; (head-&gt;index)=count; head-&gt;next=(node *)malloc(sizeof(node)); head=head-&gt;next; } fclose(fp); head-&gt;next=NULL; srand(time(NULL)); indexrand=rand()%(count+1); printf("%d\n",indexrand); for(head=mainhead;(head-&gt;next)!=NULL;head=head-&gt;next) if((head-&gt;index)==indexrand) strcpy(question,(head-&gt;string)); printf("%s\n",question); len=strlen(question); printf("%d\n",len); for(i=0;i&lt;len-1;i++) answer[i]='_'; answer[i]='\0'; printf("%s\n",answer); printf("6 chances to go\n"); for(i=0,k=6;k&gt;0;i++) { flag=0; printf("%d\n",i); scanf("%c",&amp;check); for(j=0;j&lt;(len-1);j++) { if(question[j]==check) { flag++; answer[j]=check; } } if(flag&gt;0) printf("%d chances to go\n",k); if(flag==0) { k--; printf("no common letters...%d chances to go\n",k); } printf("%s\n",answer); } } </code></pre> <p>The file dictionary.txt has only one word per line.</p> <p>While running the code, for every attempt from the user (i.e after user enters a character) the statement <code>no common letters...%d chances to go\n",k</code> is being displayed even if the <code>flag &gt; 0</code> condition is satisfied.</p> <p>How do I correct this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload