Browse Source

Commit 20 - func lade secret_word zum laden des wortes soll erstellt werden

main^2
Peter Wiebe 11 months ago
committed by Peter Wiebe
parent
commit
5a7f1d2a59
  1. 24
      src/main/c/hangman.c

24
src/main/c/hangman.c

@ -16,6 +16,7 @@ void hauptSpiel(int level);
void draw_hangman(int attempts);
void add_guessed_letter(char* guessed_letters, char guessed_letter);
char eingabe_buchstabe();
void lade_secret_word(char* secret_word, int level, char* path);
void protokoll(){
clear_screen();
@ -267,4 +268,27 @@ char eingabe_buchstabe(){
scanf(" %c", &guess);
guess = tolower(guess);
return guess;
}
void lade_secret_word(char* secret_word, int level, char* path){
FILE *file = fopen(path, "r");
int count = 0;
if ( file != NULL )
{
char line[100]; /* or other suitable maximum line size */
while (fgets(line, sizeof line, file) != NULL) /* read a line */
{
if (count == level)
{
strcpy(secret_word, line);
secret_word[strlen(secret_word) - 1] = '\0';
return;
}
else
{
count++;
}
}
fclose(file);
}
}
Loading…
Cancel
Save