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;
}