Input file erstellt

This commit is contained in:
sandnerjo102545 committed 2026-10-26 09:56:21 +01:00
1 parent e20fe38941
commit ae6116e583
1 file changed
+46
+46
View File
@@ -8,5 +8,51 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int c;
unsigned int i = 0; // Wort
unsigned int j = 0; // Zeichen im Wort
while ((c = fgetc(file)) != EOF)
{
if (c == ',' || c == ';' || c == '\n' || c == ' ')
{
if (j > 0)
{
words[i][j] = '\0';
i++;
j = 0;
if (i >= maxWordCount)
{
break;
}
}
}
else
{
// Auf Pufferüberlauf im Wort achten
if (j < MAX_WORD_LEN - 1)
{
words[i][j] = (char)toupper(c);
j++;
}
}
}
// Ans Ende \0 hinzufügen
if (j > 0 && i < maxWordCount)
{
words[i][j] = '\0';
i++;
}
// MIT CHAT GEMACHT ZUR KONTROLLE: Konsolenausgabe zur Kontrolle der eingelesenen Wörter
printf("Eingelesene Wörter (%u Stück):\n", i);
for (unsigned int idx = 0; idx < i; idx++)
{
printf("%u. Entry: %s\n", idx + 1, words[idx]);
}
return i;
}