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 <string.h>
#include <stdlib.h>
#include <time.h>
#define MAX_WORDS 100
#define MAX_WORD_LEN 50
#define SIZE 10 // Anzahl der Zeilen in der Spalte
// 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() {
const char *filename = "words.txt"; // Datei mit Wörtern
char words[MAX_WORDS][MAX_WORD_LEN];
int count = 0;
srand(time(NULL)); // Zufallszahlengenerator initialisieren
FILE *file = fopen(filename, "r");
if (!file) {
printf("Fehler: Datei %s nicht gefunden!\n", filename);
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]);
}
char column[SIZE];
createColumn(column);
showColumn(column);
return 0;
}