Click here to Skip to main content
15,886,067 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Dump file creation Pin
den2k8830-Oct-14 0:37
professionalden2k8830-Oct-14 0:37 
GeneralRe: Dump file creation Pin
HungryCPPDev30-Oct-14 20:37
HungryCPPDev30-Oct-14 20:37 
AnswerRe: Dump file creation Pin
bert_r30-Oct-14 5:16
bert_r30-Oct-14 5:16 
GeneralRe: Dump file creation Pin
HungryCPPDev30-Oct-14 20:36
HungryCPPDev30-Oct-14 20:36 
QuestionC code : read infomation of USB Pin
Member 1119126829-Oct-14 15:36
Member 1119126829-Oct-14 15:36 
GeneralRe: C code : read infomation of USB Pin
PIEBALDconsult29-Oct-14 17:30
mvePIEBALDconsult29-Oct-14 17:30 
AnswerRe: C code : read infomation of USB Pin
Vaclav Naydenov29-Oct-14 21:32
Vaclav Naydenov29-Oct-14 21:32 
Questionhangman code in C Pin
Member 1118939529-Oct-14 10:56
Member 1118939529-Oct-14 10:56 
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...


C#
#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_word[count] = guess;
            correct_guesses++;
            printf("\n**************************************************************\n\n");
            printf("Good choice!\n\n");

               if( correct_guesses == num_letters )
               {
                  puts( "\n\nCONGRATULATIONS! You guessed the word!" );
                  printf( "WORD: %s\n\n", visible_word );
                  exit( 0 );
               }

               correct_flag = 1;
            }

         }

      if( correct_flag == 0 )
      {
         incorrect_letters[tries] = guess;
         tries++;
         printf("\n**************************************************************\n\n");
         printf("Bad choice!\n\n");

      }

      /* reset flags */
      repeat_flag  = 0;
      correct_flag = 0;


   }

   puts( "You did not guess the word." );
   printf( "WORD: %s\n\n", visible_word );


}
if (choice='w'){

      printf( "\nWhat word have you chosen?:\t " );

      scanf( "%s", &guessword );

      if(guessword==word){
      printf("CONGRATULATIONS! You guessed the word!");}
      else{ printf("nops");
      }
      }

return 0;
}

SuggestionRe: hangman code in C Pin
Richard MacCutchan29-Oct-14 22:27
mveRichard MacCutchan29-Oct-14 22:27 
GeneralRe: hangman code in C Pin
Member 1118939529-Oct-14 22:54
Member 1118939529-Oct-14 22:54 
GeneralRe: hangman code in C Pin
Richard MacCutchan30-Oct-14 1:56
mveRichard MacCutchan30-Oct-14 1:56 
GeneralRe: hangman code in C Pin
CPallini30-Oct-14 7:33
mveCPallini30-Oct-14 7:33 
GeneralRe: hangman code in C Pin
Richard MacCutchan30-Oct-14 22:27
mveRichard MacCutchan30-Oct-14 22:27 
QuestionRe: hangman code in C Pin
David Crow31-Oct-14 4:32
David Crow31-Oct-14 4:32 
QuestionConvert unicode string into ascii text with numeric character references Pin
Leif Simon Goodwin29-Oct-14 5:15
Leif Simon Goodwin29-Oct-14 5:15 
QuestionCustomized virtual drive Pin
lrtsenar29-Oct-14 3:47
lrtsenar29-Oct-14 3:47 
AnswerRe: Customized virtual drive Pin
Richard MacCutchan29-Oct-14 3:54
mveRichard MacCutchan29-Oct-14 3:54 
Questionc program Pin
Member 1118930829-Oct-14 0:40
Member 1118930829-Oct-14 0:40 
AnswerRe: c program Pin
Richard MacCutchan29-Oct-14 3:52
mveRichard MacCutchan29-Oct-14 3:52 
QuestionRe: c program Pin
CPallini29-Oct-14 4:36
mveCPallini29-Oct-14 4:36 
GeneralRe: c program Pin
PIEBALDconsult29-Oct-14 4:52
mvePIEBALDconsult29-Oct-14 4:52 
AnswerRe: c program Pin
Stefan_Lang30-Oct-14 0:20
Stefan_Lang30-Oct-14 0:20 
Question"Network Access: Allow anonymous SID/Name translation" ,a am attempting to get this via the registry but cant find the key,how can I get thisvalue ,tks Pin
kxjhcs25-Oct-14 21:04
kxjhcs25-Oct-14 21:04 
AnswerRe: "Network Access: Allow anonymous SID/Name translation" ,a am attempting to get this via the registry but cant find the key,how can I get thisvalue ,tks Pin
Richard MacCutchan25-Oct-14 22:13
mveRichard MacCutchan25-Oct-14 22:13 
QuestionHow to constructor a storage class to store Tree data in C++ Pin
shanmugarajaa25-Oct-14 5:20
shanmugarajaa25-Oct-14 5:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.