generated from freudenreichan/info2Praktikum-Wortsalat
Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/sandnerjo102545/info_2_wordsalad
This commit is contained in:
commit
7b7d8986f0
1 file changed
+46
@@ -8,5 +8,51 @@
|
|||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
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;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user