This commit is contained in:
engelpa103619 committed 2026-10-26 12:32:21 +01:00
1 parent 93db739464
commit 2e24fdcec3
6 files changed
+163 -2

No files matched your search

+37
View File
@@ -4,9 +4,46 @@
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
int leseEinWort(FILE *file, char zielWort[])
{
int c;
int i = 0;
while((c = fgetc(file)) != EOF) // liest aus Textdatei und überprüft ob End Of File ist
{
if(isalpha(c) != 0)
{
if(i < MAX_WORD_LEN - 1) // -1 wegen '\0'
{
zielWort[i] = (char)toupper(c); // Für Großbuchstaben
i++;
}
}
else if(i > 0)
{
zielWort[i] = '\0';
return 1;
}
}
if(i > 0) // Datei endet direkt nach ein WOrt ohne folgendes Leerzeichen oder so
{
zielWort[i] = '\0';
return 1;
}
return 0;
}
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int anzahl = 0;
while((leseEinWort(file, words[anzahl])) == 1 && anzahl < maxWordCount)
{
anzahl++;
}
return anzahl;
}