Merge branch 'master' into feature-main-init
This commit is contained in:
commit
e703f70e42
1 file changed
+29
-1
@@ -8,5 +8,33 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
|
unsigned int wordCount=0;// die beiden Zähler also hier fertige wörter werden hier gespeichert
|
||||||
|
unsigned int letterCount=0;// zählt die gespeicherten zeichen der aktuellen wörter
|
||||||
|
int character;
|
||||||
|
|
||||||
}
|
//ungültige parameter müssen abgefragt werden
|
||||||
|
if (file == NULL || words == NULL || maxWordCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// datei zeichen für zeichen lesen & fgetc (file get character) E0F (end of file)
|
||||||
|
while (wordCount < maxWordCount && (character = fgetc(file)) != EOF)
|
||||||
|
{
|
||||||
|
//leerräume tc trennen die wörter
|
||||||
|
if (isspace(character) || character == ',' || character == ';') {
|
||||||
|
if (letterCount > 0) {
|
||||||
|
words[wordCount] [letterCount] = '\0';
|
||||||
|
wordCount++;
|
||||||
|
letterCount=0;
|
||||||
|
}
|
||||||
|
} else if (letterCount < MAX_WORD_LEN -1 ) {
|
||||||
|
words[wordCount] [letterCount] = (char)toupper (character);// to uppercase
|
||||||
|
letterCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// letzes wort speicher, auch ohne trennzeichen am datei ende
|
||||||
|
if (letterCount > 0 && wordCount < maxWordCount) {
|
||||||
|
words[wordCount] [letterCount] = '\0';
|
||||||
|
wordCount++;
|
||||||
|
}
|
||||||
|
return (int)wordCount;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user