generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc80769399 | ||
|
|
9f0c315134 | ||
|
|
7d518049a1 |
No files matched your search
File renamed without changes.
+35
-1
@@ -4,9 +4,43 @@
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||||
|
// Test 123
|
||||||
// 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 = 0;
|
||||||
|
int count = 0;
|
||||||
|
int letterCount = 0;
|
||||||
|
while (count < maxWordCount)
|
||||||
|
{
|
||||||
|
while ((c = fgetc(file)) != EOF) //Leerzeichen prüfen
|
||||||
|
{
|
||||||
|
if (isspace(c) || !isalpha(c)) {
|
||||||
|
if (letterCount > 0) {
|
||||||
|
break; //Wort fertig eingelesen
|
||||||
|
}
|
||||||
|
|
||||||
|
continue; // mehrere Leerzeichen oder Sonderzeichen überspringen
|
||||||
|
}
|
||||||
|
|
||||||
|
if (letterCount < MAX_WORD_LEN - 1) //wörter Buchstabenweise einlesen
|
||||||
|
{
|
||||||
|
words[count][letterCount] = (char)toupper(c);
|
||||||
|
letterCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (letterCount == 0) {
|
||||||
|
break; //kein weiteres Wort gefunden
|
||||||
|
}
|
||||||
|
|
||||||
|
words[count][letterCount] = '\0';
|
||||||
|
letterCount = 0;
|
||||||
|
count++;
|
||||||
|
|
||||||
|
if (c == EOF) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
+14
-4
@@ -1,5 +1,15 @@
|
|||||||
Yeti,Nessie Werwolf; Vampir
|
Yeti
|
||||||
|
Nessie
|
||||||
|
Werwolf
|
||||||
|
Vampir
|
||||||
Monster
|
Monster
|
||||||
Hydra;Frankenstein
|
Hydra
|
||||||
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
Frankenstein
|
||||||
Gespenst, Oger
|
Dracula
|
||||||
|
KingKong
|
||||||
|
Gremlin
|
||||||
|
Kobold
|
||||||
|
Hexe
|
||||||
|
Poltergeist
|
||||||
|
Gespenst
|
||||||
|
Oger
|
||||||
Reference in new issue
Block a user