hangman code in C
-
hello guys, i have to write a simple project ... it is a hangman code in C# i have this...but when I run it... i keeps printing twice some sentences... if anybody can help me... and if the user type something different from l ..when it is asked...everything goes wrong...
#include <stdio.h>
#include <string.h>/* contant declarations */
#define NUM_TRIES_ALLOWED 10/* function prototypes */
main()
{
/* variable declarations */
int num_letters = 0, /* length of word char array */
count = 0, /* for word char array */
tries = 0, /* total tries user has used */
num_vis_chars = 0, /* # of visible characters */
correct_guesses = 0, /* # of correct guesses */
correct_flag = 0, /* was guess correct? */
repeat_flag = 0, /* was guess a repeat? */
choice;char guess,guessword;
/* array declarations */
char word[255] = " ";
char incorrect_letters[255] = " ";
/* get word */
puts( "Enter a word for player to guess." );
gets( word );printf("Ready to start!\n");
num_letters = strlen( word );
char visible_word[num_letters]; /* displays correct guesses *//* initialize visble_word */
for( count = 0; count < num_letters; count++ )
visible_word[count] = '*';visible_word[num_letters] = '\0';
if (guess == visible_word[count]){
while( tries < NUM_TRIES_ALLOWED )
{printf( "The word is: %s\\n\\n", visible\_word ); printf("Number of turns remaining: %d", NUM\_TRIES\_ALLOWED-tries); printf("\\nWould you like to guess the word \[w\] or guess a letter \[l\]:"); choice = getchar(); if (choice=='l'){ printf( "\\nWhat letter have you chosen?:\\t " ); scanf( " %c", &guess );} /\* match guess against previous guesses \*/ for( count = 0; count < num\_letters; count++ ) if( guess == visible\_word\[count\] || guess == incorrect\_letters\[count\] ) { repeat\_flag = 1; correct\_flag = 1; break; } if( repeat\_flag == 0 ) /\* check for matches in string \*/ for( count = 0; count < num\_letters; count++ ) { if( guess == word\[count\] ) { visible\_wo
-
hello guys, i have to write a simple project ... it is a hangman code in C# i have this...but when I run it... i keeps printing twice some sentences... if anybody can help me... and if the user type something different from l ..when it is asked...everything goes wrong...
#include <stdio.h>
#include <string.h>/* contant declarations */
#define NUM_TRIES_ALLOWED 10/* function prototypes */
main()
{
/* variable declarations */
int num_letters = 0, /* length of word char array */
count = 0, /* for word char array */
tries = 0, /* total tries user has used */
num_vis_chars = 0, /* # of visible characters */
correct_guesses = 0, /* # of correct guesses */
correct_flag = 0, /* was guess correct? */
repeat_flag = 0, /* was guess a repeat? */
choice;char guess,guessword;
/* array declarations */
char word[255] = " ";
char incorrect_letters[255] = " ";
/* get word */
puts( "Enter a word for player to guess." );
gets( word );printf("Ready to start!\n");
num_letters = strlen( word );
char visible_word[num_letters]; /* displays correct guesses *//* initialize visble_word */
for( count = 0; count < num_letters; count++ )
visible_word[count] = '*';visible_word[num_letters] = '\0';
if (guess == visible_word[count]){
while( tries < NUM_TRIES_ALLOWED )
{printf( "The word is: %s\\n\\n", visible\_word ); printf("Number of turns remaining: %d", NUM\_TRIES\_ALLOWED-tries); printf("\\nWould you like to guess the word \[w\] or guess a letter \[l\]:"); choice = getchar(); if (choice=='l'){ printf( "\\nWhat letter have you chosen?:\\t " ); scanf( " %c", &guess );} /\* match guess against previous guesses \*/ for( count = 0; count < num\_letters; count++ ) if( guess == visible\_word\[count\] || guess == incorrect\_letters\[count\] ) { repeat\_flag = 1; correct\_flag = 1; break; } if( repeat\_flag == 0 ) /\* check for matches in string \*/ for( count = 0; count < num\_letters; count++ ) { if( guess == word\[count\] ) { visible\_wo
-
my debugger screen is grey, I tried to do this....but I couldnt
-
my debugger screen is grey, I tried to do this....but I couldnt
-
I cannot even get your code to compile so I have no idea how you are managing to run it.
:-D My up-vote for trying.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
:-D My up-vote for trying.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
hello guys, i have to write a simple project ... it is a hangman code in C# i have this...but when I run it... i keeps printing twice some sentences... if anybody can help me... and if the user type something different from l ..when it is asked...everything goes wrong...
#include <stdio.h>
#include <string.h>/* contant declarations */
#define NUM_TRIES_ALLOWED 10/* function prototypes */
main()
{
/* variable declarations */
int num_letters = 0, /* length of word char array */
count = 0, /* for word char array */
tries = 0, /* total tries user has used */
num_vis_chars = 0, /* # of visible characters */
correct_guesses = 0, /* # of correct guesses */
correct_flag = 0, /* was guess correct? */
repeat_flag = 0, /* was guess a repeat? */
choice;char guess,guessword;
/* array declarations */
char word[255] = " ";
char incorrect_letters[255] = " ";
/* get word */
puts( "Enter a word for player to guess." );
gets( word );printf("Ready to start!\n");
num_letters = strlen( word );
char visible_word[num_letters]; /* displays correct guesses *//* initialize visble_word */
for( count = 0; count < num_letters; count++ )
visible_word[count] = '*';visible_word[num_letters] = '\0';
if (guess == visible_word[count]){
while( tries < NUM_TRIES_ALLOWED )
{printf( "The word is: %s\\n\\n", visible\_word ); printf("Number of turns remaining: %d", NUM\_TRIES\_ALLOWED-tries); printf("\\nWould you like to guess the word \[w\] or guess a letter \[l\]:"); choice = getchar(); if (choice=='l'){ printf( "\\nWhat letter have you chosen?:\\t " ); scanf( " %c", &guess );} /\* match guess against previous guesses \*/ for( count = 0; count < num\_letters; count++ ) if( guess == visible\_word\[count\] || guess == incorrect\_letters\[count\] ) { repeat\_flag = 1; correct\_flag = 1; break; } if( repeat\_flag == 0 ) /\* check for matches in string \*/ for( count = 0; count < num\_letters; count++ ) { if( guess == word\[count\] ) { visible\_wo
Member 11189395 wrote:
i have to write a simple project ... it is a hangman code in C#
If this is true, then you should be in the C# forum. Otherwise, what you have shown looks like C code.
Member 11189395 wrote:
i have this...but when I run it... i keeps printing twice some sentences...
Have you stepped through the code using the debugger? Are you using Visual Studio, or some other IDE?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles