Skip to content

Instantly share code, notes, and snippets.

@mauricioaniche
Created January 12, 2015 14:21
Show Gist options
  • Save mauricioaniche/d859d17fd635b52bf8e1 to your computer and use it in GitHub Desktop.
Save mauricioaniche/d859d17fd635b52bf8e1 to your computer and use it in GitHub Desktop.
Forca - Funções - 1
#include <stdio.h>
#include <string.h>
void abertura() {
printf("/****************/\n");
printf("/ Jogo de Forca */\n");
printf("/****************/\n\n");
}
int main() {
char palavrasecreta[20];
sprintf(palavrasecreta, "MELANCIA");
int acertou = 0;
int enforcou = 0;
char chutes[26];
int tentativas = 0;
abertura();
do {
for(int i = 0; i < strlen(palavrasecreta); i++) {
int achou = 0;
for(int j = 0; j < tentativas; j++) {
if(chutes[j] == palavrasecreta[i]) {
achou = 1;
break;
}
}
if(achou) {
printf("%c ", palavrasecreta[i]);
} else {
printf("_ ");
}
}
printf("\n");
char chute;
printf("Qual letra? ");
scanf(" %c", &chute);
chutes[tentativas] = chute;
tentativas++;
} while (!acertou && !enforcou);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment