Input fertig mit Makefile für Input

This commit is contained in:
dehmfl103364 committed 2026-10-16 20:11:55 +02:00
1 parent 0ad0165c1a
commit fe390a6f5f
2 files changed
+42 -3

No files matched your search

+33 -3
View File
@@ -6,7 +6,37 @@
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// 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){
char lineRead[MAX_LINE_LEN] = {};
char *splitters = ",; \n";
int wordsRead = 0;
while(fgets(lineRead,MAX_LINE_LEN,file) != NULL && wordsRead < maxWordCount){
char *token = strtok(lineRead, splitters);
while(token != NULL && wordsRead < maxWordCount){
strcpy(words[wordsRead],token);
//Kleinbuchstaben -> Grossbuchstaben
int len = strlen(words[wordsRead]);
for(int i = 0; i < len; i++){ //müsste einen kleinbustaben am ende haben
if(islower(words[wordsRead][i])){
words[wordsRead][i] = toupper(words[wordsRead][i]);
}
}
wordsRead++;
token = strtok(NULL, splitters);
}
}
return wordsRead;
}
}