Start_Windows/input.c aktualisiert

This commit is contained in:
Simon Schuerer 2025-10-31 08:14:09 +00:00
parent b7e729182c
commit 70236c1e01

View File

@ -1,12 +1,25 @@
#include <stdio.h>
#include "input.h"
#include <string.h>
#include <ctype.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
#define MAX_WORDS 100
#define MAX_WORD_LEN 20
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int main() {
FILE *file = fopen("words.txt", "r");
if (!file) {
perror("Datei konnte nicht geöffnet werden");
return 1;
}
char words[MAX_WORDS][MAX_WORD_LEN];
int wordCount = readWords(file, words, MAX_WORDS);
fclose(file);
printf("Es wurden %d Wörter eingelesen:\n", wordCount);
for (int i = 0; i < wordCount; i++) {
printf("%s\n", words[i]);
}
return 0;
}