Browse Source

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

remotes/origin/peter^2
Peter Wiebe 11 months ago
parent
commit
6bc8c8dfc5
  1. 24
      src/main/c/hangman.c

24
src/main/c/hangman.c

@ -17,6 +17,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();
@ -269,3 +270,26 @@ char eingabe_buchstabe(){
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