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

  • Home
  • SEARCH
  • 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 6203877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:59:31+00:00 2026-05-24T04:59:31+00:00

I’m having a little problem modifying an array in C. I have two arrays,

  • 0

I’m having a little problem modifying an array in C. I have two arrays, c1 and c2.

I want to manually fill the array c2 by typing the words array c1 contains. The user types a letter and if this letter is found in c1, the program fixes this letter in the appropriate place in c2. If the letter doesn’t belong to c1, it does nothing. It’s just like a “guess the word” game. Here is a sketch:

c1 = MARRON

c2: ******
Type a letter: E


c2: ******
Type a letter: A


c2: *A****
Type a letter: O


c2: *A**O*
Type a letter: P


c2:*A**O*
Type a letter: M


c2: MA**O*
Type a letter: N


c2: MA**ON
Type a letter: R

c2: MARRON

You win.

My code doesn’t really following the sketch above. My problem is printing the asterisks and the letters at the right time. I also found out that the program replaces the last character '\0' with an asterisk even though i kept a condition to prevent that.
Here’ my code:

void complete( char *c2, char c1[], int letter ) {
    int i = 0;
    for( i = 0; i < strlen( c1 ) - 1; i++ )
        if( c1[ i ] == '\0' ) {
            c2[ i ] = '\0';
        }
        else if( letter != c1[ i ] && c2[ i ] != '*' );



        else if ( letter == c1[ i ] ) {
            c2[ i ] = letter;
            c2[ i + 1 ] = '\0';  
        }
        else if (letter != word[ i ] )
            c2[ i ] = '*';
    c2[ i + 1 ] = '\0'; 
}

int main(){
    char c1[] = "ORANGE";
    int length = strlen(c1);

    char *c2 = NULL;
    c2 = malloc(length * (sizeof(c1));

    while( 1 ){
        printf( "What is the secret word?:  ");
        printf( "%s\n", c2 );
        printf( "Propose a letter:  ");
        letter = lirecaracter();//it just reads a character

        char *suite = NULL; 
        suite = strchr(c1, letter );
        if( suite != NULL ){
            complete( c2, c1, letter );
        }

        if( strcmp( c1, c2 ) == 0 ){
            printf( "\n You won, congrats\n" );
            exit( 0 );
        }

    }

}

Thanks.

  • 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-24T04:59:32+00:00Added an answer on May 24, 2026 at 4:59 am

    Pseudocode:

      WordGuessGame(target[1..n], buffer[1..n], input[1..m])
       1. for i := 1 to n do
       2.    buffer[i] := '*'
       3. print buffer
       4. for i := 1 to m do
       5.    for j = 1 to n do
       6.       if target[j] = input[i] then
       7.          buffer[j] := input[i]
       8.    if buffer = target then
       9.       print "You win!"
      10.       return
      11.    else print buffer
      12. print "You lose..."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.