Created
January 12, 2015 19:16
-
-
Save mauricioaniche/43137829f5ba0c3f9480 to your computer and use it in GitHub Desktop.
Forca - Capítulo de Funções - 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void abertura() { | |
printf("/****************/\n"); | |
printf("/ Jogo de Forca */\n"); | |
printf("/****************/\n\n"); | |
} | |
void chuta(char chutes[], int* tentativas) { | |
char chute; | |
printf("Qual letra? "); | |
scanf(" %c", &chute); | |
chutes[*tentativas] = chute; | |
(*tentativas)++; | |
} | |
int main() { | |
char palavrasecreta[20]; | |
sprintf(palavrasecreta, "MELANCIA"); | |
int acertou = 0; | |
int enforcou = 0; | |
char chutes[26]; | |
int tentativas = 0; | |
abertura(); | |
do { | |
printf("Você já deu %d chutes\n", tentativas); | |
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"); | |
chuta(chutes, &tentativas); | |
} while (!acertou && !enforcou); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment