Thread: What am I missing here? (c programming)
i can't find word , hint messing up. here's code:
if printf("hint: %s", word); , same hint after word = get_word(num_players, player_turn); (same hint), prints fine.code:if (num_players != 0) { word = get_word(num_players, player_turn); word_length = strlen(word); correct_guesses = (char *) malloc( word_length + 1 ); hint = get_hint(num_players); } else exit(exit_success); /* erase correct_guesses & wrong_guesses */ (int = 0; < word_length; i++ ) correct_guesses[i] = '-'; correct_guesses[word_length] = '\0'; (int = 0; < incorrect_tries; i++ ) wrong_guesses[i] = ' '; wrong_guesses[incorrect_tries] = '\0'; wg = wrong_guesses; /* game... repeats until player has guessed word or has reached incorrect_tries - 7 incorrect tries completes hangman */ for(;;) { clrscrn(); draw_hangman(num_wrong_guesses); printf("hint: %s\n", hint); printf("word: %s\n", correct_guesses); printf("incorrect tries: %s\n", wrong_guesses);
lower, when print inside for(;doesn't. word_length gets set 2. i'm guessing because word , hint pointers, not actual word-arrays. please confirm me?
so... in clearer fashion... 2 questions:
word_length set 2 because word pointer?
why word , hint print out fine after being initialized, not print out correctly inside for(;loop?
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] What am I missing here? (c programming)
Ubuntu
Comments
Post a Comment