Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3405860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:33:26+00:00 2026-05-18T05:33:26+00:00

I have spent many hours working on this program that is supposed to play

  • 0

I have spent many hours working on this program that is supposed to play a game of hangman.

The assignment is as follows:
In this modified game of Hangman, the computer chooses a secret word and the player must guess letters in the word. The secret word is displayed as a series of *’s (the number of *’s displayed indicates the number of letters in the word). Each time the player guesses a letter in the word, the corresponding *’s are replaced with the letters correctly guessed so far. The game ends when the player correctly guesses the entire word (player wins) or when the player uses up all of his turns (player loses). The player will be allowed a maximum of 7 incorrect guesses.

I have come pretty far with it, but feel like I am messing up in several elementary places. I am trying to debug it, but cannot get past the part where I get an error in the main function every time I pass the function ‘findChars’ saying that it “makes pointer from integer without a cast in argument 2.”

I apologize for all the reading, but any help would be great. Thank you.

<

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include <time.h> /* contains prototype for function time */
#define MAX 10


int findChars(char* gameWord[], char secretWord[], int length);

int main (void) {
const int numberOfWords = 20;
int length;
srand((unsigned)time(NULL)); //generate a random seed based on time so it's different every time
int ran = rand()% numberOfWords; //Generate a random number between 0 to numberOfWords - 1
char* dictionary[] = {"who", "lives", "in","a", "pineapple", "under","the", "sea", "absorbant",
            "and", "yellow", "porous","is", "he", "sponge","bob", "square","pants","crabby","patties"}; //array of word strings

printf("%s\n", dictionary[ran]);

printf("Welcome to HANGMAN.\n\n You will be asked to guess the computer's secret word. The word will be displayed as a number of *'s.\n Every time you guess a letter correctly, that letter will be shown in its correct position in the word.  \nIf you guess incorrectly, the number of tries you have left will be decremented.  \nYou will be given a maximum of 7 incorrect guesses.\n");

length=strlen(dictionary[ran]);
printf("%d\n", length);
char secretWord[MAX];
secretWord[length]=*dictionary[ran];

char* gameWord[length];

int i;
for (i=0; i<length; i++){
    gameWord[i]= "*";
}

for (i=0; i<length; i++){
    printf("%s", gameWord[i]);
}
printf("\n");
printf("7 turns left \nEnter a letter:    \n");

while(findChars(&gameWord[length], secretWord[length], length)!=0) {
    (findChars(&gameWord[length], secretWord[length], length));
}
    printf("6 turns left \nEnter a letter:    \n");

while(findChars(&gameWord[length], secretWord[length], length)!=0) {
    (findChars(&gameWord[length], secretWord[length], length));
}
    printf("5 turns left \nEnter a letter:    \n");

while(findChars(&gameWord[length], secretWord[length], length)!=0) {
    (findChars(&gameWord[length], secretWord[length], length));
}
    printf("4 turns left \nEnter a letter:    \n");

while(findChars(&gameWord[length], secretWord[length], length)!=0) {
    (findChars(&gameWord[length], secretWord[length], length));
}
    printf("3 turns left \nEnter a letter:    \n");

while(findChars(&gameWord[length], secretWord[length], length)!=0) {
    (findChars(&gameWord[length], secretWord[length], length));
}
    printf("2 turns left \nEnter a letter:    \n");

while(findChars(&gameWord[length], secretWord[length], length)!=0) {
    (findChars(&gameWord[length], secretWord[length], length));
}
    printf("1 turns left \nEnter a letter:    \n");

while(findChars(&gameWord[length], secretWord[length], length)!=0) {
    (findChars(&gameWord[length], secretWord[length], length));
}
    printf("Sorry, no more turns left. The secret word was ???");

return 0;
}

//PRE: findChar inputs the character we are looking for, the string we are looking in.
//POST: the function outputs the number of occurances of the said character in the said array

int findChars(char* gameWord[],char secretWord[], int length) {
int i;
char character[MAX];
    while((getchar()) != '\n'){
        character[0]=getchar();
        for (i=0; i<length; i++){
            if (secretWord[i]==character[0]){
                strncpy(gameWord[i],secretWord[i],1);
                for (i=0; i<length; i++){
                    printf("%s", gameWord[i]);
                    return 1;
                }
            }
            else
                return 0;
        }
    return 0;
    }
return 0;
}

>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:33:26+00:00Added an answer on May 18, 2026 at 5:33 am

    Try changing:

    char secretWord[MAX];
    secretWord[length]=*dictionary[ran];
    

    and

    char* gameWord[length];
    

    to

    char* secretWord = dictionary[ran];
    

    and

    char gameWord[length];
    

    Right now your only assigning the first character of dictionary[ran] to the character at position of length in secretWord.

    (If you’re goint to print gameWord you’ll also have to allocate space and set a null terminator for it).

    Then change

    findChars(&gameWord[length], secretWord[length], length)
    

    to:

    findChars(gameWord, secretWord, length)
    

    as you right now are passing a char to a function expecting a char*. You’ll also need to change the signature of findChars to:

    int findChars(char* gameWord, char* secretWord, int length)
    

    There’s a lot of other things to object to, but this should get you started. Things to look at:

    • Putting the seven while(findChars... into a loop
    • Don’t use strncpy(gameWord[i],secretWord[i],1); to assign one char from one string to another
    • Incorrect printf formatting
    • The for (i=0; i<length; i++){-loop in findChars returns in the first iteration
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.