2 Commits
Author SHA1 Message Date
fischerch103508 30c53ce8b9 input.c errors behoben 2026-10-13 20:33:40 +02:00
fischerch103508 61c60ebffd input angepasst 2026-10-13 19:45:13 +02:00
+15 -17
View File
@@ -8,27 +8,25 @@
// 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)
{ {
char puffer[MAX_LINE_LEN]; char puffer[MAX_WORD_LEN];
char *teiler = " ,;\n"; char *teiler = " ,;";
char *token; char *token;
FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei unsigned int wordCount = 0;
words_txt_speicherort = fopen("words.txt","r"); //word.txt öffnen fgets(puffer, MAX_LINE_LEN, file);
if(words_txt_speicherort == NULL) //Abbruch falls words.txt nicht existieren würde token = strtok(puffer, teiler);
while(token != NULL && wordCount < maxWordCount)
{ {
return -1; strncpy(words[wordCount], token, MAX_WORD_LEN -1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
wordCount++;
token =strtok(NULL, teiler);
} }
fgets(puffer, MAX_LINE_LEN, words_txt_speicherort); //speichert alle Zeichen der words.txt datei in den speicher return wordCount;
token = strtok(puffer, teiler); //Trennt das erste Wort der Zeichenkette, abhängig von den Teilerbedingungen
while(token != NULL)
words = token; //speichert nur das einzelne Word in das words array; Problem: Laufindex der global gespeichert werden müsste; wie springe ich beim 2ten Funktionsaufruf zum nächsten Wort
int fclose(words_txt_speicherort);
} }