Start_Windows/game.c aktualisiert

This commit is contained in:
Simon Schuerer 2025-11-03 13:49:12 +00:00
parent c5cee836e0
commit 6f92d66b10

View File

@ -1,31 +1,29 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <stdlib.h>
#include <time.h>
#define MAX_WORDS 100 #define SIZE 10 // Anzahl der Zeilen in der Spalte
#define MAX_WORD_LEN 50
// Erzeugt eine Spalte mit zufälligen Buchstaben
void createColumn(char column[SIZE]) {
for (int i = 0; i < SIZE; i++) {
column[i] = 'A' + rand() % 26; // Zufälliger Buchstabe A-Z
}
}
// Gibt die Spalte aus
void showColumn(char column[SIZE]) {
for (int i = 0; i < SIZE; i++) {
printf("%c\n", column[i]);
}
}
int main() { int main() {
const char *filename = "words.txt"; // Datei mit Wörtern srand(time(NULL)); // Zufallszahlengenerator initialisieren
char words[MAX_WORDS][MAX_WORD_LEN];
int count = 0;
FILE *file = fopen(filename, "r"); char column[SIZE];
if (!file) { createColumn(column);
printf("Fehler: Datei %s nicht gefunden!\n", filename); showColumn(column);
return 1;
}
// Wörter aus Datei einlesen
while (fscanf(file, "%49s", words[count]) == 1 && count < MAX_WORDS) {
count++;
}
fclose(file);
// Wörter ausgeben
printf("Eingelesene Wörter:\n");
for (int i = 0; i < count; i++) {
printf("%s\n", words[i]);
}
return 0; return 0;
} }