suggestion game hangman

This is a discussion on suggestion game hangman within the C Programming forums, part of the General Programming Boards category; Hi, I'm trying to make a simple hangman game, where you must find the word. I am blocked at this ...

  1. #1
    Registered User blob84's Avatar
    Join Date
    Jun 2010
    Posts
    46

    suggestion game hangman

    Hi, I'm trying to make a simple hangman game, where you must find the word.
    I am blocked at this piece of code:
    This do the job once, I want do this:
    1-get char from stdin;
    2-replace underscore with char given if exists;
    3-add single char in a new char array;
    4-when the word doesn't contain underscore anymore, stop.
    Do you have some idea?
    Code:
    #include <stdio.h>
    #include <string.h>
    
    char *replaceChar ( char *string );
    int main () {
    	char s[] = "cane";
    	char *newstr;
    	//newstr = replaceChar( s );
    	
    	newstr = replaceChar( s );
    	printf ( "%d\ns=%s\nnewstr=%s\n", strlen( s ), s, newstr); 
    	
    }
    
    char *replaceChar ( char *string ) {
    	int x;
    	int lung;
    	char ch;
    	lung = strlen ( string );
    	printf ( "insert: " );
    	ch = getchar();
    		
    	for ( x = 0; x < lung; x++ ) {
    		if ( ch != string[x] ) {
    			string[x] = '_';
    		}
    	}
    	return string;
    }
    Last edited by blob84; 08-04-2010 at 07:59 AM.

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    I would invest in some while loops right about now. The sort that execute until a certain condition is met, f. ex. the string does not contain any underscores.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [freefps]Tactical Assault coders needed
    By Sickmind in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 05-07-2010, 05:06 PM
  2. Event driven game engine
    By abachler in forum Game Programming
    Replies: 9
    Last Post: 12-01-2009, 05:03 AM
  3. Confused Beginner - hangman game
    By goodfornothing in forum C++ Programming
    Replies: 4
    Last Post: 11-30-2009, 10:06 PM
  4. Hangman game problems
    By necroak in forum C Programming
    Replies: 2
    Last Post: 11-15-2009, 02:47 PM
  5. ok, game suggestion for me?
    By Nutshell in forum Game Programming
    Replies: 8
    Last Post: 10-15-2002, 11:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21