Implementation input.c, Tests bestanden.
This commit is contained in:
1 parent
fc2a51c72e
commit
8097b5ae51
4 files changed
+79
-58
No files matched your search
+22
-1
@@ -4,9 +4,30 @@
|
||||
|
||||
// TODO:
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
|
||||
// Wörter werden durh ",", ", " oder ";" getrennt
|
||||
// Read words from file and store in 'words' array
|
||||
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
int word_count = 0;
|
||||
char *teiler = " ;,\n";
|
||||
char buffer[MAX_WORD_LEN * maxWordCount];
|
||||
char *token;
|
||||
|
||||
while(fgets(buffer, MAX_WORD_LEN * maxWordCount, file) != NULL){
|
||||
token = strtok(buffer, teiler);
|
||||
|
||||
while(token != NULL){
|
||||
strncpy(words[word_count], token, MAX_WORD_LEN);
|
||||
char *s = words[word_count];
|
||||
while (*s != '\0') {
|
||||
*s = toupper((unsigned char) *s);
|
||||
s++;
|
||||
}
|
||||
word_count++;
|
||||
token = strtok(NULL, teiler);
|
||||
}
|
||||
}
|
||||
|
||||
return word_count;
|
||||
}
|
||||
Reference in new issue
Block a user